Learn R Programming

pprof (version 1.0.3)

linear_cre: Main Function for fitting correlated random effect linear model

Description

Fit a correlated random effect linear model via lmer from the lme4 package.

Usage

linear_cre(data, Y.char, wb.char, other.char = NULL, ProvID.char, ...)

Value

A list of objects with S3 class "linear_cre":

coefficient

a list containing the estimated coefficients: FE, the fixed effects for each predictor and the intercept, and RE, the random effects for each provider.

variance

a list containing the variance estimates: FE, the variance-covariance matrix of the fixed effect coefficients, and RE, the variance of the random 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 processed data used to fit the model, sorted by the provider identifier. This includes the within-group (*_within) and between-group (*_bar) components for variables specified in wb.char. For categorical covariates, it 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

the log-likelihood.

AIC

Akaike information criterion.

BIC

Bayesian information criterion.

Arguments

data

a data frame containing all variables.

Y.char

a character string specifying the column name of the response variable in the data.

wb.char

a character vector specifying covariates to be decomposed into within (*_within) and between (*_bar) components.

other.char

a character vector specifying additional covariates to include in the model without decomposition.

ProvID.char

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

...

additional arguments passed to lmer for further customization.

Details

Fit a correlated random effect linear model using lmer with a Mundlak within–between decomposition for selected covariates. For each decomposed covariate \(Z_k\), the function constructs \(Z_{k,\mathrm{bar},i} = \frac{1}{n_i}\sum_j Z_{k,ij}\) (the group mean, "between") and \(Z_{k,\mathrm{within},ij} = Z_{k,ij} - Z_{k,\mathrm{bar},i}\) (the within-group deviation), and estimates $$Y_{ij} = \mu + \alpha_i + \sum_k \beta_{k,W} Z_{k,\mathrm{within},ij} + \sum_k \beta_{k,B} Z_{k,\mathrm{bar},i} + \mathbf{X}_{ij}^\top\gamma + \varepsilon_{ij},$$ where \(\alpha_i \sim \mathcal{N}(0,\sigma_\alpha^2)\) is a random intercept.

The function creates, for every name in wb.char, two columns: <var>_bar (group mean within ProvID.char) and <var>_within (observation minus its group mean). The fitted model is:


  Y ~ <all *_within> + <all *_bar> + <other.char> + (1 | ProvID)

In addition to these input formats, all arguments from the lmer function can be modified via ..., allowing for customization of model fitting options such as controlling the optimization method or adjusting convergence criteria. By default, the model is fitted using REML (restricted maximum likelihood).

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

Bates D, Maechler M, Bolker B, Walker S (2015). Fitting Linear Mixed-Effects Models Using lme4. Journal of Statistical Software, 67(1), 1-48.

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)
outcome.char <- colnames(data)[1]
ProvID.char <- colnames(data)[2]
wb.char <- c("z1", "z2")
other.char <- c("z3", "z4", "z5")

# Fit a correlated random effect linear model
fit_cre <- linear_cre(data = data, Y.char = outcome.char, ProvID.char = ProvID.char,
wb.char = wb.char, other.char = other.char)

Run the code above in your browser using DataLab