Learn R Programming

pprof (version 1.0.2)

linear_fe: 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"
)

Value

A list of objects with S3 class "linear_fe":

coefficient

a list containing the estimated coefficients: beta, the fixed effects for each predictor, and gamma, the effect for each provider.

variance

a list containing the variance estimates: beta, the variance-covariance matrix of the predictor coefficients, and gamma, the variance of the provider effects.

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.

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 id().

data

a data frame containing the variables named in the formula, or the columns specified by Y.char, Z.char, and ProvID.char.

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 data.

Z.char

a character vector specifying the column names of the covariates in the data.

ProvID.char

a character string specifying the column name of the provider identifier in the data.

option.gamma.var

a character string specifying the method to calculate the variance of provider effects gamma, must be "full" or "simplified". You can specify just the initial letter.

  • "simplified" (default) calculating the simplified variance of provider effects assuming regression coefficients are known. This approach is suitable for large datasets where the results of the full and simplified methods are similar, or when the full method may become unstable due to complex settings.

  • "full" considering the correlation between provider effects and regression coefficients.

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.

References

Hsiao, C. (2022). Analysis of panel data (No. 64). Cambridge university press.

See Also

data_check

Examples

Run this code
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)

Run the code above in your browser using DataLab