npmmApproximation

 

Description of function:

With this R function (npmmApproximation), users can calculate the NPMM-approximated fixed effects, random effect (co)variances, and level-1/level-2 heteroscedasticity components in MLM, for a specified K and H (if one model is fit), or a specified range of K and H (if multiple models are fit, e.g., in the context of model selection).  This function accommodates any number of level-1 and level-2 predictors in the general NPMM of Equation (15) (see Rights & Sterba, 2016). Users first run NPMM models in Mplus for each desired combination of number of level-1 classes (K) and level-2 classes (H) while outputting results in Mplus with the following command format:

SAVEDATA: RESULTS ARE example_HbyK.dat;

This function provides a table of results and can also produce plots such as in Figures 6 and 7 of the manuscript. Data can be manually entered (for a single K, H model) or can be read in automatically from a set of Mplus output files for multiple models (with different combinations of K and H).

Rights, J.D., & Sterba, S.K. (2016). The relationship between multilevel models and nonparametric multilevel mixture models: Discrete approximation of intraclass correlation, random coefficient distributions, and residual heteroscedasticity. British Journal of Mathematical and Statistical Psychology69, 316-343.

Input values:

Hmin = minimum value for number of level-2 classes H

Hmax = maximum value for number of level-2 classes H (if only one H is desired, set Hmin=Hmax)

Kmin = minimum value for number of level-1 classes K

Kmax = maximum value for number of level-1 classes K (if only one K is desired, set Kmin=Kmax)

nL1vars = number of level-1 variables (i.e., number of within-level slopes in Mplus output)

nL2vars = number of level-2 variables (i.e., number of between-level slopes in Mplus output)

resvar_con = TRUE or FALSE; specifies whether residual variance is constrained across all class-combination (TRUE) or is freely estimated across all class-combinations (FALSE); set to FALSE by default

Mplusoutput = file location and partial name of Mplus output files used; when reading in files, function automatically adds “HbyK.dat”

plotoutput = specifies file location and name of pdf file with approximation plots showing results across the range of H and K; if FALSE (default), no plots are produced

intslopes = (NOTE: only needed if manually entering parameter estimates for a single model; set to NA by default) vector of coefficients for all class-combination intercepts and all class-combination slopes; to be entered in the following order: (1) all intercepts going in order of increasing k (level-1 class) then increasing h (level-2 class) (e.g., k=1,h=1; k=2,h=1; k=1,h=2; k=2,h=2); (2) all within-level slopes for each class-combination (classes increasing as in (1)), e.g., xslope1_k1h1, xslope2_k1h1, xslope1_k2h1, xslope2_k2h1, etc.); (3) all between-level slopes for each class-combination (classes increasing as in (1))

resvar = (NOTE: only needed if manually entering parameter estimates for a single model; set to NA by default)  vector of class-combination residual variances (entered in the order of classes described in intslopes above)

mcwi = (NOTE: only needed if manually entering parameter estimates for a single model; set to NA by default) vector of level-1 class multinomial intercepts, entered in order of increasingk, with 0 entered for K

mcws = (NOTE: only needed if manually entering parameter estimates for a single model; set to NA by default) vector of multinomial slopes of k on h (entered in the order of classes described in intslopes above, with 0 entered for every k=K and h=H)

mcbi = (NOTE: only needed if manually entering parameter estimates for a single model; set to NA by default) vector of level-2 class multinomial intercepts, entered in order of increasing h, with 0 entered for H

R code:

npmmApproximation

 

Back Home