Location-Scale models include models for the location (mean, \(E(Y_{ij})\)) and for the scale as well (i.e., \(\sigma^2\) and \(\tau^2\)). The function to do this uses a FORTRAN program writen by Don Hedeker and Rachel Nordgren. See
Hedeker, D, & Nordren, R. (2013), MIXREGLS: A Program for Mixed-Effects Location Scale Analysis. Journal of Statistical Software, 52. http://www.jstatsoft.org/
If you use this function, I strongly recommend that you take a look at the JSS paper. The method on using mixregls in R that are described in the JSS paper don’t seem to be working (it worked a couple of years ago, but not now). I did a workaround that calls the executable file (mixreglsb.exe) within the function. I tried to make the input as similar as I could to that in Hedeker & Nordgren’s paper.
To run this wrapper function, you need the file “mixreglsb.exe” which is among the files you can download from the Journal of Statistic Software (JSS) site.
The function sets up the data and everyting else you need to run
mixreglsb.exe. The function will create a number of files on your
hardrive that in inputs to the function (i.e., mixregls.def,
You should set your working directory to the place where you saved mixreglsb.exe on your hard drive.
This program only works on PC. There is a version that work with stata. There are also a number of package in R that will fit such models using Bayesian estimation.
What is below reproduces what’s in the lecture note.
This are libraries that I used in the R_mixregls function.
library(formula.tools)
## Warning: package 'formula.tools' was built under R version 4.0.5
library(stringr)
This is where my data and the mixreglsb.exe files live:
setwd("D:/Dropbox/edps587/lectures/8 modelbuilding/MIXREGLS/hsb_example")
I will use as source the function
source("D:/Dropbox/edps587/lectures/8 modelbuilding/MIXREGLS/hsb_example/R_mixregls.R")
R_mixedregls(fo, indata, idname, outdata, outresults, save_def,
title1=NULL, title2=NULL, PNINT=NULL, RNINT=NULL, SNINT=NULL,
CONV=NULL, NQ=NULL,AQUAD=NULL, MAXIT=NULL, STD=NULL, MISS=NULL,
NCOV=NULL)
Due to constraints on my time, I did not include error checks, but I did set defaults to most of the input information.
Required input:
Options and their defaults are
# The data
indata <- read.table("hsball.txt", header=TRUE)
# A formula
fo <- formula(mathach ~ female + cSES + meanses + sector | meanses + sector | meanses + sector)
# Minimal input to run
R_mixregls(fo, indata, idname="id",
outdata="hsb_example1.dat",
outresults="hsb_example1.out",
save_def="hsb_example1.def")
## Warning in if (bsnames != "none" & wsnames != "none") {: the condition has
## length > 1 and only the first element will be used
## Warning in if (bsnames == "none" & wsnames != "none") {: the condition has
## length > 1 and only the first element will be used
## Warning in if (bsnames != "none" & wsnames == "none") {: the condition has
## length > 1 and only the first element will be used
## Warning in if (bsnames == "none" & wsnames == "none") {: the condition has
## length > 1 and only the first element will be used
## Warning in if (bsnames != "none") {: the condition has length > 1 and only the
## first element will be used
## Warning in if (wsnames != "none") {: the condition has length > 1 and only the
## first element will be used
## [1] 0
model_summaries<- readLines("hsb_example1.out")
noquote(model_summaries)
## [1] MIXREGLS: Mixed-effects Location Scale Model with BS and WS variance models
## [2]
## [3] ---------------------------
## [4] MIXREGLS.DEF specifications
## [5] ---------------------------
## [6]
## [7]
## [8]
## [9] data and output files:
## [10] hsb_example1.dat
## [11] hsb_example1.out
## [12]
## [13] CONVERGENCE CRITERION = 0.00001000
## [14] NQ = 11
## [15] QUADRATURE = 1 (0=non-adaptive, 1=adaptive)
## [16] MAXIT = 200
## [17]
## [18]
## [19] ------------
## [20] Descriptives
## [21] ------------
## [22]
## [23] Number of level-1 observations = 7185
## [24]
## [25] Number of level-2 clusters = 160
## [26]
## [27] Number of level-1 observations for each level-2 cluster
## [28] 47 25 48 20 48 30 28 35 44 33 57 62 53
## [29] 27 53 28 29 39 47 60 61 67 47 57 52 57
## [30] 38 57 42 38 52 45 47 25 55 42 43 48 46
## [31] 53 59 21 39 52 38 39 45 49 53 38 48 64
## [32] 51 43 45 41 54 41 52 53 46 64 44 45 58
## [33] 65 53 33 25 41 32 48 58 47 63 61 34 58
## [34] 28 57 66 57 45 61 53 52 37 29 25 50 31
## [35] 29 56 33 43 21 35 58 60 54 30 29 57 35
## [36] 56 56 44 55 49 53 33 28 44 52 53 48 51
## [37] 58 56 44 51 54 32 22 51 37 47 44 49 33
## [38] 30 43 35 27 14 37 41 53 61 48 48 32 32
## [39] 64 36 58 51 56 55 53 31 36 19 29 57 53
## [40] 47 35 29 59
## [41]
## [42] Dependent variable
## [43] mean min max std dev
## [44] --------------------------------------------------------
## [45] mathach 12.7479 -2.8320 24.9930 6.8782
## [46]
## [47] Mean model covariates
## [48] mean min max std dev
## [49] --------------------------------------------------------
## [50] female 0.5282 0.0000 1.0000 0.4992
## [51] cSES -0.0060 -3.6570 2.8500 0.6606
## [52] meanse 0.0061 -1.1880 0.8310 0.4136
## [53] s sec 0.4931 0.0000 1.0000 0.5000
## [54]
## [55] BS variance model covariates
## [56] mean min max std dev
## [57] --------------------------------------------------------
## [58] meanses 0.0061 -1.1880 0.8310 0.4136
## [59] secto 0.4931 0.0000 1.0000 0.5000
## [60]
## [61] WS variance model covariates
## [62] mean min max std dev
## [63] --------------------------------------------------------
## [64] meanses 0.0061 -1.1880 0.8310 0.4136
## [65] secto 0.4931 0.0000 1.0000 0.5000
## [66]
## [67]
## [68] ---------------
## [69] Starting Values
## [70] ---------------
## [71]
## [72] BETA: mean model regression coefficients
## [73] 12.7237 -1.1982 2.1521 5.2180 1.2516
## [74]
## [75] ALPHA: BS variance log-linear model regression coefficients
## [76] 0.7368 -0.1351 -0.1036
## [77]
## [78] TAU: WS variance log-linear model regression coefficients
## [79] 3.6053 -0.1351 -0.1036
## [80]
## [81] Random location (mean) effect on WS variance
## [82] -0.2355
## [83] Scale standard deviation
## [84] 0.2921
## [85]
## [86]
## [87] ------------------------------
## [88] Model without Scale Parameters
## [89] ------------------------------
## [90] Total Iterations = 5
## [91] Final Ridge value = 0.0
## [92]
## [93] Log Likelihood = -23245.116
## [94] Akaike's Information Criterion = -23254.116
## [95] Schwarz's Bayesian Criterion = -23267.954
## [96]
## [97] ==> multiplied by -2
## [98] Log Likelihood = 46490.232
## [99] Akaike's Information Criterion = 46508.232
## [100] Schwarz's Bayesian Criterion = 46535.909
## [101]
## [102]
## [103] Variable Estimate AsymStdError z-value p-value
## [104] -------- ------------ ------------ ------------ ------------
## [105] BETA (regression coefficients)
## [106] Intercpt 12.76131 0.19040 67.02520 0.00000
## [107] female -1.19680 0.16355 -7.31778 0.00000
## [108] cSES 2.15210 0.10849 19.83750 0.00000
## [109] meanse 5.29502 0.36645 14.44948 0.00000
## [110] s sec 1.14187 0.30093 3.79445 0.00015
## [111] ALPHA (BS variance parameters: log-linear model)
## [112] Intercpt 0.36352 0.26993 1.34673 0.17807
## [113] meanses -0.61541 0.47329 -1.30029 0.19350
## [114] secto 0.66294 0.37299 1.77736 0.07551
## [115] TAU (WS variance parameters: log-linear model)
## [116] Intercpt 3.60568 0.01688 213.57376 0.00000
## [117]
## [118]
## [119] ---------------------------
## [120] Model WITH Scale Parameters
## [121] ---------------------------
## [122] Total Iterations = 8
## [123] Final Ridge value = 0.0
## [124]
## [125] Log Likelihood = -23229.887
## [126] Akaike's Information Criterion = -23240.887
## [127] Schwarz's Bayesian Criterion = -23257.801
## [128]
## [129] ==> multiplied by -2
## [130] Log Likelihood = 46459.774
## [131] Akaike's Information Criterion = 46481.774
## [132] Schwarz's Bayesian Criterion = 46515.601
## [133]
## [134]
## [135] Variable Estimate AsymStdError z-value p-value
## [136] -------- ------------ ------------ ------------ ------------
## [137] BETA (regression coefficients)
## [138] Intercpt 12.75607 0.19023 67.05618 0.00000
## [139] female -1.18414 0.16535 -7.16136 0.00000
## [140] cSES 2.10338 0.10935 19.23510 0.00000
## [141] meanse 5.30121 0.36583 14.49091 0.00000
## [142] s sec 1.13597 0.30110 3.77278 0.00016
## [143] ALPHA (BS variance parameters: log-linear model)
## [144] Intercpt 0.30122 0.28398 1.06072 0.28882
## [145] meanses -0.61458 0.48076 -1.27834 0.20113
## [146] secto 0.75482 0.38209 1.97550 0.04821
## [147] TAU (WS variance parameters: log-linear model)
## [148] Intercpt 3.68163 0.02451 150.22195 0.00000
## [149] meanses -0.06877 0.04492 -1.53102 0.12577
## [150] secto -0.16140 0.03610 -4.47137 0.00001
## [151]
## [152]
## [153] -----------------------
## [154] Model WITH RANDOM Scale
## [155] -----------------------
## [156] Total Iterations = 13
## [157] Final Ridge value = 0.0
## [158]
## [159] Log Likelihood = -23226.860
## [160] Akaike's Information Criterion = -23239.860
## [161] Schwarz's Bayesian Criterion = -23259.848
## [162]
## [163] ==> multiplied by -2
## [164] Log Likelihood = 46453.720
## [165] Akaike's Information Criterion = 46479.720
## [166] Schwarz's Bayesian Criterion = 46519.697
## [167]
## [168]
## [169] Variable Estimate AsymStdError z-value p-value
## [170] -------- ------------ ------------ ------------ ------------
## [171] BETA (regression coefficients)
## [172] Intercpt 12.76475 0.19158 66.62722 0.00000
## [173] female -1.19225 0.16489 -7.23051 0.00000
## [174] cSES 2.10590 0.10935 19.25783 0.00000
## [175] meanse 5.26641 0.37035 14.22004 0.00000
## [176] s sec 1.12653 0.30011 3.75373 0.00017
## [177] ALPHA (BS variance parameters: log-linear model)
## [178] Intercpt 0.32361 0.28338 1.14196 0.25347
## [179] meanses -0.72431 0.48381 -1.49710 0.13437
## [180] secto 0.69610 0.37948 1.83437 0.06660
## [181] TAU (WS variance parameters: log-linear model)
## [182] Intercpt 3.68046 0.02523 145.88369 0.00000
## [183] meanses -0.08389 0.04680 -1.79259 0.07304
## [184] secto -0.15957 0.03723 -4.28644 0.00002
## [185] Random location (mean) effect on WS variance
## [186] Loc Eff -0.05550 0.02261 -2.45456 0.01411
## [187] Random scale standard deviation
## [188] Std Dev 0.00000 0.05637 0.00000 1.00000
readLines("MIXREGLS.EST")
## [1] " 46490.232029 5 200"
## [2] " 12.76130701 -1.19679994 2.15210274 5.29502332 1.14187382"
## [3] " 0.36352375 -0.61541315 0.66293773"
## [4] " 3.60568048"
## [5] " 0.19039565 0.16354692 0.10848656 0.36645088 0.30093226"
## [6] " 0.26992993 0.47328798 0.37298982 0.01688260"
## [7] " 46459.774169 8 200"
## [8] " 12.75607335 -1.18414112 2.10338116 5.30121164 1.13597368"
## [9] " 0.30122199 -0.61458280 0.75481967"
## [10] " 3.68163243 -0.06876921 -0.16139939"
## [11] " 0.19022965 0.16535150 0.10935121 0.36583007 0.30109727"
## [12] " 0.28397978 0.48076499 0.38209140 0.02450795 0.04491734"
## [13] " 0.03609620"
## [14] " 46453.719694 13 200"
## [15] " 12.76475336 -1.19225402 2.10590232 5.26640777 1.12652923"
## [16] " 0.32360756 -0.72431069 0.69610485"
## [17] " 3.68046178 -0.08388590 -0.15956817"
## [18] " -0.05549954 0.00000000"
## [19] " 0.19158467 0.16489220 0.10935305 0.37035123 0.30010920"
## [20] " 0.28337848 0.48380983 0.37947847 0.02522874 0.04679605"
## [21] " 0.03722625 0.02261075 0.05636692"
readLines("MIXREGLS.ITS")
## [1] " "
## [2] " ------------------------------"
## [3] " Model without Scale Parameters"
## [4] " ------------------------------"
## [5] " Newton-Raphson Iteration 1 with ridge 0.0000"
## [6] " maximum correction and derivative"
## [7] " 0.7367818130715045 6.806677179532094"
## [8] " -2 Log-Likelihood = 46494.91227"
## [9] " Newton-Raphson Iteration 2 with ridge 0.0000"
## [10] " maximum correction and derivative"
## [11] " 4.061421173448695E-02 1.710754936596036"
## [12] " -2 Log-Likelihood = 46490.25116"
## [13] " Newton-Raphson Iteration 3 with ridge 0.0000"
## [14] " maximum correction and derivative"
## [15] " 4.393220705996675E-04 7.076728457795944E-03"
## [16] " -2 Log-Likelihood = 46490.23203"
## [17] " Newton-Raphson Iteration 4 with ridge 0.0000"
## [18] " maximum correction and derivative"
## [19] " 3.381814312964789E-08 1.126814654028863E-06"
## [20] " -2 Log-Likelihood = 46490.23203"
## [21] " maximum correction and derivative"
## [22] " 2.714581092706398E-12 1.265515470194600E-11"
## [23] " -2 Log-Likelihood = 46490.23203"
## [24] " "
## [25] "---------------------------"
## [26] "Model WITH Scale Parameters"
## [27] "---------------------------"
## [28] " Newton-Raphson Iteration 1 with ridge 0.1000"
## [29] " maximum correction and derivative"
## [30] " 4.447811432647224E-02 173.7946989751461"
## [31] " -2 Log-Likelihood = 46471.73024"
## [32] " Newton-Raphson Iteration 2 with ridge 0.1000"
## [33] " maximum correction and derivative"
## [34] " 2.009347737668332E-02 41.98396601758268"
## [35] " -2 Log-Likelihood = 46461.59997"
## [36] " Newton-Raphson Iteration 3 with ridge 0.1000"
## [37] " maximum correction and derivative"
## [38] " 1.455665818444296E-02 13.97933792674917"
## [39] " -2 Log-Likelihood = 46460.19937"
## [40] " Newton-Raphson Iteration 4 with ridge 0.1000"
## [41] " maximum correction and derivative"
## [42] " 9.893940190416872E-03 6.008022058687303"
## [43] " -2 Log-Likelihood = 46459.87943"
## [44] " Newton-Raphson Iteration 5 with ridge 0.0000"
## [45] " maximum correction and derivative"
## [46] " 1.630693675599935E-02 2.850644118735827"
## [47] " -2 Log-Likelihood = 46459.80068"
## [48] " Newton-Raphson Iteration 6 with ridge 0.0000"
## [49] " maximum correction and derivative"
## [50] " 1.000870482038841E-04 1.295719541690232E-02"
## [51] " -2 Log-Likelihood = 46459.77417"
## [52] " Newton-Raphson Iteration 7 with ridge 0.0000"
## [53] " maximum correction and derivative"
## [54] " 4.466195169997806E-09 7.689367986785101E-08"
## [55] " -2 Log-Likelihood = 46459.77417"
## [56] " maximum correction and derivative"
## [57] " 5.517871166898656E-13 5.460520924316370E-12"
## [58] " -2 Log-Likelihood = 46459.77417"
## [59] " "
## [60] "-----------------------"
## [61] "Model WITH RANDOM Scale"
## [62] "-----------------------"
## [63] " Newton-Raphson Iteration 1 with ridge 0.2000"
## [64] " maximum correction and derivative"
## [65] " 0.5414275407588233 168.5249175670873"
## [66] " -2 Log-Likelihood = 46538.71040"
## [67] " Newton-Raphson Iteration 2 with ridge 0.2000"
## [68] " maximum correction and derivative"
## [69] " 5.685020642929128E-02 157.9728350028663"
## [70] " -2 Log-Likelihood = 46467.18193"
## [71] " Newton-Raphson Iteration 3 with ridge 0.2000"
## [72] " maximum correction and derivative"
## [73] " 4.077350919361512E-02 107.2041053540414"
## [74] " -2 Log-Likelihood = 46459.72990"
## [75] " Newton-Raphson Iteration 4 with ridge 0.2000"
## [76] " maximum correction and derivative"
## [77] " 2.991360956550798E-02 73.02740441339462"
## [78] " -2 Log-Likelihood = 46456.50905"
## [79] " Newton-Raphson Iteration 5 with ridge 0.2000"
## [80] " maximum correction and derivative"
## [81] " 2.312066635413046E-02 49.84290363212214"
## [82] " -2 Log-Likelihood = 46455.03298"
## [83] " Newton-Raphson Iteration 6 with ridge 0.2000"
## [84] " maximum correction and derivative"
## [85] " 2.100593133794640E-02 34.07148703133026"
## [86] " -2 Log-Likelihood = 46454.34442"
## [87] " Newton-Raphson Iteration 7 with ridge 0.2000"
## [88] " maximum correction and derivative"
## [89] " 1.374060165760982E-02 12.69742666692104"
## [90] " -2 Log-Likelihood = 46453.81682"
## [91] " Newton-Raphson Iteration 8 with ridge 0.2000"
## [92] " maximum correction and derivative"
## [93] " 6.101080892651892E-03 4.786150016436375"
## [94] " -2 Log-Likelihood = 46453.73804"
## [95] " Newton-Raphson Iteration 9 with ridge 0.2000"
## [96] " maximum correction and derivative"
## [97] " 3.756529448957055E-03 1.831968817406400"
## [98] " -2 Log-Likelihood = 46453.72447"
## [99] " Newton-Raphson Iteration 10 with ridge 0.0000"
## [100] " maximum correction and derivative"
## [101] " 1.016578203584401E-02 0.7153255276381003"
## [102] " -2 Log-Likelihood = 46453.72142"
## [103] " Newton-Raphson Iteration 11 with ridge 0.0000"
## [104] " maximum correction and derivative"
## [105] " 2.694803539915313E-05 1.521262054089423E-03"
## [106] " -2 Log-Likelihood = 46453.71969"
## [107] " Newton-Raphson Iteration 12 with ridge 0.0000"
## [108] " maximum correction and derivative"
## [109] " 3.168826613731922E-10 1.643788616334518E-08"
## [110] " -2 Log-Likelihood = 46453.71969"
## [111] " maximum correction and derivative"
## [112] " 8.281508902938399E-13 5.262457136723242E-12"
## [113] " -2 Log-Likelihood = 46453.71969"
For the following, you can change the label on the columns and read them in as data frame or you can do something like what’s below.
std1 <- readLines("MIXREGLS.RE1")
std2 <- readLines("MIXREGLS.RE2")
We use the same formula, but now set up titles
title1 <- "Example -- with titles I defined"
title2 <- "March 12, 2023"
R_mixregls(fo, indata, idname="id",
outdata="hsb_example2.dat",
outresults="hsb_example2.out",
save_def="hsb_example2.def",
title1=title1, title2=title2)
## Warning in if (bsnames != "none" & wsnames != "none") {: the condition has
## length > 1 and only the first element will be used
## Warning in if (bsnames == "none" & wsnames != "none") {: the condition has
## length > 1 and only the first element will be used
## Warning in if (bsnames != "none" & wsnames == "none") {: the condition has
## length > 1 and only the first element will be used
## Warning in if (bsnames == "none" & wsnames == "none") {: the condition has
## length > 1 and only the first element will be used
## Warning in if (bsnames != "none") {: the condition has length > 1 and only the
## first element will be used
## Warning in if (wsnames != "none") {: the condition has length > 1 and only the
## first element will be used
## [1] 0
model_summaries<- readLines("hsb_example2.out")
noquote(model_summaries)
## [1] MIXREGLS: Mixed-effects Location Scale Model with BS and WS variance models
## [2]
## [3] ---------------------------
## [4] MIXREGLS.DEF specifications
## [5] ---------------------------
## [6] Example -- with titles I defined
## [7] March 12, 2023
## [8]
## [9] data and output files:
## [10] hsb_example2.dat
## [11] hsb_example2.out
## [12]
## [13] CONVERGENCE CRITERION = 0.00001000
## [14] NQ = 11
## [15] QUADRATURE = 1 (0=non-adaptive, 1=adaptive)
## [16] MAXIT = 200
## [17]
## [18]
## [19] ------------
## [20] Descriptives
## [21] ------------
## [22]
## [23] Number of level-1 observations = 7185
## [24]
## [25] Number of level-2 clusters = 160
## [26]
## [27] Number of level-1 observations for each level-2 cluster
## [28] 47 25 48 20 48 30 28 35 44 33 57 62 53
## [29] 27 53 28 29 39 47 60 61 67 47 57 52 57
## [30] 38 57 42 38 52 45 47 25 55 42 43 48 46
## [31] 53 59 21 39 52 38 39 45 49 53 38 48 64
## [32] 51 43 45 41 54 41 52 53 46 64 44 45 58
## [33] 65 53 33 25 41 32 48 58 47 63 61 34 58
## [34] 28 57 66 57 45 61 53 52 37 29 25 50 31
## [35] 29 56 33 43 21 35 58 60 54 30 29 57 35
## [36] 56 56 44 55 49 53 33 28 44 52 53 48 51
## [37] 58 56 44 51 54 32 22 51 37 47 44 49 33
## [38] 30 43 35 27 14 37 41 53 61 48 48 32 32
## [39] 64 36 58 51 56 55 53 31 36 19 29 57 53
## [40] 47 35 29 59
## [41]
## [42] Dependent variable
## [43] mean min max std dev
## [44] --------------------------------------------------------
## [45] mathach 12.7479 -2.8320 24.9930 6.8782
## [46]
## [47] Mean model covariates
## [48] mean min max std dev
## [49] --------------------------------------------------------
## [50] female 0.5282 0.0000 1.0000 0.4992
## [51] cSES -0.0060 -3.6570 2.8500 0.6606
## [52] meanse 0.0061 -1.1880 0.8310 0.4136
## [53] s sec 0.4931 0.0000 1.0000 0.5000
## [54]
## [55] BS variance model covariates
## [56] mean min max std dev
## [57] --------------------------------------------------------
## [58] meanses 0.0061 -1.1880 0.8310 0.4136
## [59] secto 0.4931 0.0000 1.0000 0.5000
## [60]
## [61] WS variance model covariates
## [62] mean min max std dev
## [63] --------------------------------------------------------
## [64] meanses 0.0061 -1.1880 0.8310 0.4136
## [65] secto 0.4931 0.0000 1.0000 0.5000
## [66]
## [67]
## [68] ---------------
## [69] Starting Values
## [70] ---------------
## [71]
## [72] BETA: mean model regression coefficients
## [73] 12.7237 -1.1982 2.1521 5.2180 1.2516
## [74]
## [75] ALPHA: BS variance log-linear model regression coefficients
## [76] 0.7368 -0.1351 -0.1036
## [77]
## [78] TAU: WS variance log-linear model regression coefficients
## [79] 3.6053 -0.1351 -0.1036
## [80]
## [81] Random location (mean) effect on WS variance
## [82] -0.2355
## [83] Scale standard deviation
## [84] 0.2921
## [85]
## [86]
## [87] ------------------------------
## [88] Model without Scale Parameters
## [89] ------------------------------
## [90] Total Iterations = 5
## [91] Final Ridge value = 0.0
## [92]
## [93] Log Likelihood = -23245.116
## [94] Akaike's Information Criterion = -23254.116
## [95] Schwarz's Bayesian Criterion = -23267.954
## [96]
## [97] ==> multiplied by -2
## [98] Log Likelihood = 46490.232
## [99] Akaike's Information Criterion = 46508.232
## [100] Schwarz's Bayesian Criterion = 46535.909
## [101]
## [102]
## [103] Variable Estimate AsymStdError z-value p-value
## [104] -------- ------------ ------------ ------------ ------------
## [105] BETA (regression coefficients)
## [106] Intercpt 12.76131 0.19040 67.02520 0.00000
## [107] female -1.19680 0.16355 -7.31778 0.00000
## [108] cSES 2.15210 0.10849 19.83750 0.00000
## [109] meanse 5.29502 0.36645 14.44948 0.00000
## [110] s sec 1.14187 0.30093 3.79445 0.00015
## [111] ALPHA (BS variance parameters: log-linear model)
## [112] Intercpt 0.36352 0.26993 1.34673 0.17807
## [113] meanses -0.61541 0.47329 -1.30029 0.19350
## [114] secto 0.66294 0.37299 1.77736 0.07551
## [115] TAU (WS variance parameters: log-linear model)
## [116] Intercpt 3.60568 0.01688 213.57376 0.00000
## [117]
## [118]
## [119] ---------------------------
## [120] Model WITH Scale Parameters
## [121] ---------------------------
## [122] Total Iterations = 8
## [123] Final Ridge value = 0.0
## [124]
## [125] Log Likelihood = -23229.887
## [126] Akaike's Information Criterion = -23240.887
## [127] Schwarz's Bayesian Criterion = -23257.801
## [128]
## [129] ==> multiplied by -2
## [130] Log Likelihood = 46459.774
## [131] Akaike's Information Criterion = 46481.774
## [132] Schwarz's Bayesian Criterion = 46515.601
## [133]
## [134]
## [135] Variable Estimate AsymStdError z-value p-value
## [136] -------- ------------ ------------ ------------ ------------
## [137] BETA (regression coefficients)
## [138] Intercpt 12.75607 0.19023 67.05618 0.00000
## [139] female -1.18414 0.16535 -7.16136 0.00000
## [140] cSES 2.10338 0.10935 19.23510 0.00000
## [141] meanse 5.30121 0.36583 14.49091 0.00000
## [142] s sec 1.13597 0.30110 3.77278 0.00016
## [143] ALPHA (BS variance parameters: log-linear model)
## [144] Intercpt 0.30122 0.28398 1.06072 0.28882
## [145] meanses -0.61458 0.48076 -1.27834 0.20113
## [146] secto 0.75482 0.38209 1.97550 0.04821
## [147] TAU (WS variance parameters: log-linear model)
## [148] Intercpt 3.68163 0.02451 150.22195 0.00000
## [149] meanses -0.06877 0.04492 -1.53102 0.12577
## [150] secto -0.16140 0.03610 -4.47137 0.00001
## [151]
## [152]
## [153] -----------------------
## [154] Model WITH RANDOM Scale
## [155] -----------------------
## [156] Total Iterations = 13
## [157] Final Ridge value = 0.0
## [158]
## [159] Log Likelihood = -23226.860
## [160] Akaike's Information Criterion = -23239.860
## [161] Schwarz's Bayesian Criterion = -23259.848
## [162]
## [163] ==> multiplied by -2
## [164] Log Likelihood = 46453.720
## [165] Akaike's Information Criterion = 46479.720
## [166] Schwarz's Bayesian Criterion = 46519.697
## [167]
## [168]
## [169] Variable Estimate AsymStdError z-value p-value
## [170] -------- ------------ ------------ ------------ ------------
## [171] BETA (regression coefficients)
## [172] Intercpt 12.76475 0.19158 66.62722 0.00000
## [173] female -1.19225 0.16489 -7.23051 0.00000
## [174] cSES 2.10590 0.10935 19.25783 0.00000
## [175] meanse 5.26641 0.37035 14.22004 0.00000
## [176] s sec 1.12653 0.30011 3.75373 0.00017
## [177] ALPHA (BS variance parameters: log-linear model)
## [178] Intercpt 0.32361 0.28338 1.14196 0.25347
## [179] meanses -0.72431 0.48381 -1.49710 0.13437
## [180] secto 0.69610 0.37948 1.83437 0.06660
## [181] TAU (WS variance parameters: log-linear model)
## [182] Intercpt 3.68046 0.02523 145.88369 0.00000
## [183] meanses -0.08389 0.04680 -1.79259 0.07304
## [184] secto -0.15957 0.03723 -4.28644 0.00002
## [185] Random location (mean) effect on WS variance
## [186] Loc Eff -0.05550 0.02261 -2.45456 0.01411
## [187] Random scale standard deviation
## [188] Std Dev 0.00000 0.05637 0.00000 1.00000
# Simpler formula
fo <- formula(mathach ~ female + cSES + meanses + sector | sector | sector)
R_mixregls(fo, indata, idname="id",
outdata="hsb_example3.dat",
outresults="hsb_example3.out",
save_def="hsb_example3.def",
title1=title1, title2=title2)
## [1] 0
model_summaries<- readLines("hsb_example3.out")
noquote(model_summaries)
## [1] MIXREGLS: Mixed-effects Location Scale Model with BS and WS variance models
## [2]
## [3] ---------------------------
## [4] MIXREGLS.DEF specifications
## [5] ---------------------------
## [6] Example -- with titles I defined
## [7] March 12, 2023
## [8]
## [9] data and output files:
## [10] hsb_example3.dat
## [11] hsb_example3.out
## [12]
## [13] CONVERGENCE CRITERION = 0.00001000
## [14] NQ = 11
## [15] QUADRATURE = 1 (0=non-adaptive, 1=adaptive)
## [16] MAXIT = 200
## [17]
## [18]
## [19] ------------
## [20] Descriptives
## [21] ------------
## [22]
## [23] Number of level-1 observations = 7185
## [24]
## [25] Number of level-2 clusters = 160
## [26]
## [27] Number of level-1 observations for each level-2 cluster
## [28] 47 25 48 20 48 30 28 35 44 33 57 62 53
## [29] 27 53 28 29 39 47 60 61 67 47 57 52 57
## [30] 38 57 42 38 52 45 47 25 55 42 43 48 46
## [31] 53 59 21 39 52 38 39 45 49 53 38 48 64
## [32] 51 43 45 41 54 41 52 53 46 64 44 45 58
## [33] 65 53 33 25 41 32 48 58 47 63 61 34 58
## [34] 28 57 66 57 45 61 53 52 37 29 25 50 31
## [35] 29 56 33 43 21 35 58 60 54 30 29 57 35
## [36] 56 56 44 55 49 53 33 28 44 52 53 48 51
## [37] 58 56 44 51 54 32 22 51 37 47 44 49 33
## [38] 30 43 35 27 14 37 41 53 61 48 48 32 32
## [39] 64 36 58 51 56 55 53 31 36 19 29 57 53
## [40] 47 35 29 59
## [41]
## [42] Dependent variable
## [43] mean min max std dev
## [44] --------------------------------------------------------
## [45] mathach 12.7479 -2.8320 24.9930 6.8782
## [46]
## [47] Mean model covariates
## [48] mean min max std dev
## [49] --------------------------------------------------------
## [50] female 0.5282 0.0000 1.0000 0.4992
## [51] cSES -0.0060 -3.6570 2.8500 0.6606
## [52] meanse 0.0061 -1.1880 0.8310 0.4136
## [53] s sec 0.4931 0.0000 1.0000 0.5000
## [54]
## [55] BS variance model covariates
## [56] mean min max std dev
## [57] --------------------------------------------------------
## [58] sector 0.4931 0.0000 1.0000 0.5000
## [59]
## [60] WS variance model covariates
## [61] mean min max std dev
## [62] --------------------------------------------------------
## [63] sector 0.4931 0.0000 1.0000 0.5000
## [64]
## [65]
## [66] ---------------
## [67] Starting Values
## [68] ---------------
## [69]
## [70] BETA: mean model regression coefficients
## [71] 12.7237 -1.1982 2.1521 5.2180 1.2516
## [72]
## [73] ALPHA: BS variance log-linear model regression coefficients
## [74] 0.7368 -0.1435
## [75]
## [76] TAU: WS variance log-linear model regression coefficients
## [77] 3.6053 -0.1435
## [78]
## [79] Random location (mean) effect on WS variance
## [80] -0.2355
## [81] Scale standard deviation
## [82] 0.2921
## [83]
## [84]
## [85] ------------------------------
## [86] Model without Scale Parameters
## [87] ------------------------------
## [88] Total Iterations = 5
## [89] Final Ridge value = 0.0
## [90]
## [91] Log Likelihood = -23245.987
## [92] Akaike's Information Criterion = -23253.987
## [93] Schwarz's Bayesian Criterion = -23266.288
## [94]
## [95] ==> multiplied by -2
## [96] Log Likelihood = 46491.975
## [97] Akaike's Information Criterion = 46507.975
## [98] Schwarz's Bayesian Criterion = 46532.576
## [99]
## [100]
## [101] Variable Estimate AsymStdError z-value p-value
## [102] -------- ------------ ------------ ------------ ------------
## [103] BETA (regression coefficients)
## [104] Intercpt 12.73315 0.19422 65.56017 0.00000
## [105] female -1.18610 0.16329 -7.26391 0.00000
## [106] cSES 2.15245 0.10848 19.84209 0.00000
## [107] meanse 5.32645 0.35611 14.95714 0.00000
## [108] s sec 1.21622 0.29641 4.10323 0.00004
## [109] ALPHA (BS variance parameters: log-linear model)
## [110] Intercpt 0.47707 0.24742 1.92816 0.05384
## [111] sector 0.48174 0.33601 1.43370 0.15166
## [112] TAU (WS variance parameters: log-linear model)
## [113] Intercpt 3.60555 0.01688 213.58522 0.00000
## [114]
## [115]
## [116] ---------------------------
## [117] Model WITH Scale Parameters
## [118] ---------------------------
## [119] Total Iterations = 8
## [120] Final Ridge value = 0.0
## [121]
## [122] Log Likelihood = -23231.983
## [123] Akaike's Information Criterion = -23240.983
## [124] Schwarz's Bayesian Criterion = -23254.821
## [125]
## [126] ==> multiplied by -2
## [127] Log Likelihood = 46463.966
## [128] Akaike's Information Criterion = 46481.966
## [129] Schwarz's Bayesian Criterion = 46509.643
## [130]
## [131]
## [132] Variable Estimate AsymStdError z-value p-value
## [133] -------- ------------ ------------ ------------ ------------
## [134] BETA (regression coefficients)
## [135] Intercpt 12.72843 0.19418 65.54845 0.00000
## [136] female -1.17497 0.16530 -7.10808 0.00000
## [137] cSES 2.09420 0.10915 19.18642 0.00000
## [138] meanse 5.33153 0.35561 14.99268 0.00000
## [139] s sec 1.21307 0.29628 4.09436 0.00004
## [140] ALPHA (BS variance parameters: log-linear model)
## [141] Intercpt 0.41388 0.26134 1.58370 0.11326
## [142] sector 0.57342 0.34286 1.67249 0.09443
## [143] TAU (WS variance parameters: log-linear model)
## [144] Intercpt 3.69051 0.02381 155.00854 0.00000
## [145] sector -0.17980 0.03394 -5.29738 0.00000
## [146]
## [147]
## [148] -----------------------
## [149] Model WITH RANDOM Scale
## [150] -----------------------
## [151] Total Iterations = 13
## [152] Final Ridge value = 0.0
## [153]
## [154] Log Likelihood = -23229.776
## [155] Akaike's Information Criterion = -23240.776
## [156] Schwarz's Bayesian Criterion = -23257.689
## [157]
## [158] ==> multiplied by -2
## [159] Log Likelihood = 46459.552
## [160] Akaike's Information Criterion = 46481.552
## [161] Schwarz's Bayesian Criterion = 46515.379
## [162]
## [163]
## [164] Variable Estimate AsymStdError z-value p-value
## [165] -------- ------------ ------------ ------------ ------------
## [166] BETA (regression coefficients)
## [167] Intercpt 12.71287 0.19553 65.01714 0.00000
## [168] female -1.18231 0.16496 -7.16737 0.00000
## [169] cSES 2.09559 0.10919 19.19167 0.00000
## [170] meanse 5.19390 0.35856 14.48540 0.00000
## [171] s sec 1.25849 0.29435 4.27545 0.00002
## [172] ALPHA (BS variance parameters: log-linear model)
## [173] Intercpt 0.44338 0.26507 1.67268 0.09439
## [174] sector 0.49148 0.34672 1.41749 0.15634
## [175] TAU (WS variance parameters: log-linear model)
## [176] Intercpt 3.69211 0.02437 151.52359 0.00000
## [177] sector -0.18336 0.03484 -5.26214 0.00000
## [178] Random location (mean) effect on WS variance
## [179] Loc Eff -0.04760 0.02279 -2.08862 0.03674
## [180] Random scale standard deviation
## [181] Std Dev 0.00000 0.04851 0.00000 1.00000
# Simpler formula
fo <- formula(mathach ~ female + cSES + meanses + sector | none | sector)
R_mixregls(fo, indata, idname="id",
outdata="hsb_example4.dat",
outresults="hsb_example4.out",
save_def="hsb_example4.def",
title1="No BS predictors",
title2="Nels 23 schools")
## [1] 0
model_summaries<- readLines("hsb_example4.out")
noquote(model_summaries)
## [1] MIXREGLS: Mixed-effects Location Scale Model with BS and WS variance models
## [2]
## [3] ---------------------------
## [4] MIXREGLS.DEF specifications
## [5] ---------------------------
## [6] No BS predictors
## [7] Nels 23 schools
## [8]
## [9] data and output files:
## [10] hsb_example4.dat
## [11] hsb_example4.out
## [12]
## [13] CONVERGENCE CRITERION = 0.00001000
## [14] NQ = 11
## [15] QUADRATURE = 1 (0=non-adaptive, 1=adaptive)
## [16] MAXIT = 200
## [17]
## [18]
## [19] ------------
## [20] Descriptives
## [21] ------------
## [22]
## [23] Number of level-1 observations = 7185
## [24]
## [25] Number of level-2 clusters = 160
## [26]
## [27] Number of level-1 observations for each level-2 cluster
## [28] 47 25 48 20 48 30 28 35 44 33 57 62 53
## [29] 27 53 28 29 39 47 60 61 67 47 57 52 57
## [30] 38 57 42 38 52 45 47 25 55 42 43 48 46
## [31] 53 59 21 39 52 38 39 45 49 53 38 48 64
## [32] 51 43 45 41 54 41 52 53 46 64 44 45 58
## [33] 65 53 33 25 41 32 48 58 47 63 61 34 58
## [34] 28 57 66 57 45 61 53 52 37 29 25 50 31
## [35] 29 56 33 43 21 35 58 60 54 30 29 57 35
## [36] 56 56 44 55 49 53 33 28 44 52 53 48 51
## [37] 58 56 44 51 54 32 22 51 37 47 44 49 33
## [38] 30 43 35 27 14 37 41 53 61 48 48 32 32
## [39] 64 36 58 51 56 55 53 31 36 19 29 57 53
## [40] 47 35 29 59
## [41]
## [42] Dependent variable
## [43] mean min max std dev
## [44] --------------------------------------------------------
## [45] mathach 12.7479 -2.8320 24.9930 6.8782
## [46]
## [47] Mean model covariates
## [48] mean min max std dev
## [49] --------------------------------------------------------
## [50] female 0.5282 0.0000 1.0000 0.4992
## [51] cSES -0.0060 -3.6570 2.8500 0.6606
## [52] meanse 0.0061 -1.1880 0.8310 0.4136
## [53] s sec 0.4931 0.0000 1.0000 0.5000
## [54]
## [55] WS variance model covariates
## [56] mean min max std dev
## [57] --------------------------------------------------------
## [58] 0.4931 0.0000 1.0000 0.5000
## [59]
## [60]
## [61] ---------------
## [62] Starting Values
## [63] ---------------
## [64]
## [65] BETA: mean model regression coefficients
## [66] 12.7237 -1.1982 2.1521 5.2180 1.2516
## [67]
## [68] ALPHA: BS variance log-linear model regression coefficients
## [69] 0.7368
## [70]
## [71] TAU: WS variance log-linear model regression coefficients
## [72] 3.6053 -0.1435
## [73]
## [74] Random location (mean) effect on WS variance
## [75] -0.2355
## [76] Scale standard deviation
## [77] 0.2921
## [78]
## [79]
## [80] ------------------------------
## [81] Model without Scale Parameters
## [82] ------------------------------
## [83] Total Iterations = 3
## [84] Final Ridge value = 0.0
## [85]
## [86] Log Likelihood = -23247.035
## [87] Akaike's Information Criterion = -23254.035
## [88] Schwarz's Bayesian Criterion = -23264.798
## [89]
## [90] ==> multiplied by -2
## [91] Log Likelihood = 46494.069
## [92] Akaike's Information Criterion = 46508.069
## [93] Schwarz's Bayesian Criterion = 46529.595
## [94]
## [95]
## [96] Variable Estimate AsymStdError z-value p-value
## [97] -------- ------------ ------------ ------------ ------------
## [98] BETA (regression coefficients)
## [99] Intercpt 12.72370 0.20728 61.38366 0.00000
## [100] female -1.19822 0.16207 -7.39339 0.00000
## [101] cSES 2.15206 0.10847 19.84097 0.00000
## [102] meanse 5.21831 0.35266 14.79718 0.00000
## [103] s sec 1.25143 0.29221 4.28271 0.00002
## [104] ALPHA (BS variance parameters: log-linear model)
## [105] Intercpt 0.73682 0.16073 4.58427 0.00000
## [106] TAU (WS variance parameters: log-linear model)
## [107] Intercpt 3.60534 0.01688 213.60407 0.00000
## [108]
## [109]
## [110] ---------------------------
## [111] Model WITH Scale Parameters
## [112] ---------------------------
## [113] Total Iterations = 8
## [114] Final Ridge value = 0.0
## [115]
## [116] Log Likelihood = -23233.432
## [117] Akaike's Information Criterion = -23241.432
## [118] Schwarz's Bayesian Criterion = -23253.732
## [119]
## [120] ==> multiplied by -2
## [121] Log Likelihood = 46466.864
## [122] Akaike's Information Criterion = 46482.864
## [123] Schwarz's Bayesian Criterion = 46507.465
## [124]
## [125]
## [126] Variable Estimate AsymStdError z-value p-value
## [127] -------- ------------ ------------ ------------ ------------
## [128] BETA (regression coefficients)
## [129] Intercpt 12.71760 0.21019 60.50668 0.00000
## [130] female -1.18955 0.16386 -7.25943 0.00000
## [131] cSES 2.09468 0.10913 19.19483 0.00000
## [132] meanse 5.20587 0.35399 14.70643 0.00000
## [133] s sec 1.25389 0.29284 4.28178 0.00002
## [134] ALPHA (BS variance parameters: log-linear model)
## [135] Intercpt 0.74257 0.15974 4.64863 0.00000
## [136] TAU (WS variance parameters: log-linear model)
## [137] Intercpt 3.68876 0.02375 155.29841 0.00000
## [138] -0.17699 0.03390 -5.22130 0.00000
## [139]
## [140]
## [141] -----------------------
## [142] Model WITH RANDOM Scale
## [143] -----------------------
## [144] Total Iterations = 13
## [145] Final Ridge value = 0.0
## [146]
## [147] Log Likelihood = -23230.811
## [148] Akaike's Information Criterion = -23240.811
## [149] Schwarz's Bayesian Criterion = -23256.187
## [150]
## [151] ==> multiplied by -2
## [152] Log Likelihood = 46461.622
## [153] Akaike's Information Criterion = 46481.622
## [154] Schwarz's Bayesian Criterion = 46512.373
## [155]
## [156]
## [157] Variable Estimate AsymStdError z-value p-value
## [158] -------- ------------ ------------ ------------ ------------
## [159] BETA (regression coefficients)
## [160] Intercpt 12.69783 0.20951 60.60710 0.00000
## [161] female -1.19523 0.16360 -7.30574 0.00000
## [162] cSES 2.09579 0.10916 19.19873 0.00000
## [163] meanse 5.06392 0.35227 14.37512 0.00000
## [164] s sec 1.30655 0.29158 4.48098 0.00001
## [165] ALPHA (BS variance parameters: log-linear model)
## [166] Intercpt 0.73128 0.15977 4.57714 0.00000
## [167] TAU (WS variance parameters: log-linear model)
## [168] Intercpt 3.69069 0.02441 151.21299 0.00000
## [169] -0.18146 0.03496 -5.19000 0.00000
## [170] Random location (mean) effect on WS variance
## [171] Loc Eff -0.05162 0.02269 -2.27563 0.02287
## [172] Random scale standard deviation
## [173] Std Dev 0.00000 0.05033 0.00000 1.00000