linear_fe {pprof} | R Documentation |
Main function for fitting the fixed effect linear model
Description
Fit a fixed effect linear model via profile likelihood.
Usage
linear_fe(
formula = NULL,
data = NULL,
Y = NULL,
Z = NULL,
ProvID = NULL,
Y.char = NULL,
Z.char = NULL,
ProvID.char = NULL,
option.gamma.var = "simplified"
)
Arguments
formula |
a two-sided formula object describing the model to be fitted,
with the response variable on the left of a ~ operator and covariates on the right,
separated by + operators. The fixed effect of the provider identifier is specified using |
data |
a data frame containing the variables named in the |
Y |
a numeric vector representing the response variable. |
Z |
a matrix or data frame representing the covariates, which can include both numeric and categorical variables. |
ProvID |
a numeric vector representing the provider identifier. |
Y.char |
a character string specifying the column name of the response variable in the |
Z.char |
a character vector specifying the column names of the covariates in the |
ProvID.char |
a character string specifying the column name of the provider identifier in the |
option.gamma.var |
a character string specifying the method to calculate the variance of provider effects
|
Details
This function is used to fit a fixed effect linear model of the form:
Y_{ij} = \gamma_i + \mathbf{Z}_{ij}^\top\boldsymbol\beta + \epsilon_{ij}
where Y_{ij}
is the continuous outcome for individual j
in provider i
, \gamma_i
is the provider-specific effect,
\mathbf{Z}_{ij}
are the covariates, and \boldsymbol\beta
is the vector of coefficients for the covariates.
The function accepts three different input formats:
a formula and dataset, where the formula is of the form response ~ covariates + id(provider)
, with provider
representing the provider identifier;
a dataset along with the column names of the response, covariates, and provider identifier;
or the outcome vector \boldsymbol{Y}
, the covariate matrix or data frame \mathbf{Z}
, and the provider identifier vector.
If issues arise during model fitting, consider using the data_check
function to perform a data quality check,
which can help identify missing values, low variation in covariates, high-pairwise correlation, and multicollinearity.
For datasets with missing values, this function automatically removes observations (rows) with any missing values before fitting the model.
Value
A list of objects with S3 class "linear_fe"
:
coefficient |
a list containing the estimated coefficients:
|
variance |
a list containing the variance estimates:
|
sigma |
the residual standard error. |
fitted |
the fitted values of each individual. |
observation |
the original response of each individual. |
residuals |
the residuals of each individual, that is response minus fitted values. |
linear_pred |
the linear predictor of each individual. |
data_include |
the data used to fit the model, sorted by the provider identifier. For categorical covariates, this includes the dummy variables created for all categories except the reference level. |
char_list |
a list of the character vectors representing the column names for the response variable, covariates, and provider identifier. For categorical variables, the names reflect the dummy variables created for each category. |
Loglkd |
log likelihood. |
AIC |
Akaike information criterion. |
BIC |
Bayesian information criterion. |
References
Hsiao, C. (2022). Analysis of panel data (No. 64). Cambridge university press.
See Also
Examples
data(ExampleDataLinear)
outcome <- ExampleDataLinear$Y
covar <- ExampleDataLinear$Z
ProvID <- ExampleDataLinear$ProvID
data <- data.frame(outcome, ProvID, covar)
covar.char <- colnames(covar)
outcome.char <- colnames(data)[1]
ProvID.char <- colnames(data)[2]
formula <- as.formula(paste("outcome ~", paste(covar.char, collapse = " + "), "+ id(ProvID)"))
# Fit fixed linear effect model using three input formats
fit_fe1 <- linear_fe(Y = outcome, Z = covar, ProvID = ProvID)
fit_fe2 <- linear_fe(data = data, Y.char = outcome.char,
Z.char = covar.char, ProvID.char = ProvID.char)
fit_fe3 <- linear_fe(formula, data)