logis_re {pprof} | R Documentation |
Main Function for fitting the random effect logistic model
Description
Fit a random effect logistic model via glmer
from the lme4
package.
Usage
logis_re(
formula = NULL,
data = NULL,
Y = NULL,
Z = NULL,
ProvID = NULL,
Y.char = NULL,
Z.char = NULL,
ProvID.char = NULL,
...
)
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 random 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 |
... |
additional arguments passed to |
Details
This function is used to fit a random effect logistic model of the form:
\text{logit}(P(Y_{ij} = 1 \mid \alpha_i, \mathbf{Z}_{ij})) = \mu + \alpha_i + \mathbf{Z}_{ij}^\top \boldsymbol{\beta},
where Y_{ij}
is the binary outcome for individual j
in provider i
,
\mu
is the overall intercept, \alpha_i
is the random effect for provider i
,
\mathbf{Z}_{ij}
are the covariates, and \boldsymbol\beta
is the vector of coefficients for the covariates.
The model is fitted by overloading the glmer
function from the lme4
package.
Three different input formats are accepted:
a formula and dataset, where the formula is of the form response ~ covariates + (1 | 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.
In addition to these input formats, all arguments from the glmer
function can be modified via ...
,
allowing for customization of model fitting options.
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 "logis_re"
:
coefficient |
a list containing the estimated coefficients:
|
variance |
a list containing the variance estimates:
|
fitted |
the predicted probability of each observation having a response of 1. |
observation |
the original response of each individual. |
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 |
the log-likelihood. |
AIC |
Akaike information criterion. |
BIC |
Bayesian information criterion. |
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
Examples
data(ExampleDataBinary)
outcome <- ExampleDataBinary$Y
covar <- ExampleDataBinary$Z
ProvID <- ExampleDataBinary$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 = " + "), "+ (1|ProvID)"))
# Fit logistic linear effect model using three input formats
fit_re1 <- logis_re(Y = outcome, Z = covar, ProvID = ProvID)
fit_re2 <- logis_re(data = data, Y.char = outcome.char,
Z.char = covar.char, ProvID.char = ProvID.char)
fit_re3 <- logis_re(formula, data)