Here fit location-scale model to 23 schools from nels. The R belows will run the program mixreglsb.exe from R. The code makes use of the function R_mixregls.txt which is a function that I wrote to help you set up the input to mixreglsb.exe and than run the program.

The mixreglsb.txt use software described in the following paper. The R described in the paper no longer works; however, you can download programs and examples from the paper’s web-site. There are quite a few number of files, but you only need mixreglsb.exe.

Hedeker, D, & Nordgren, R. (2013), MIXREGLS: A Program for Mixed-Effects Location Scale Analysis. Journal of Statistical Software, 52. http://www.jstatsoft.org/

I suggest that you read the above paper to better understand what is going on.

The mixreglsb.exe only fits random intercept models, but an extended verision is described in the paper Nordrend, Hedeker, Donton & Yang (2019) in Statistics in Medicine. There is an appendix that contians information for fitting the extended version in SAS/NLMIXED and merlin in STATA. A R version is in development at the time the paper was written.

A few things if you run the R_mixregls function:

  1. Data are numeric. If you have any varibles with character values these should be dummy, effect or otherwise coded.
  2. The program mixreglsb.exe runs on a PC.
  3. I have not written in what to do with missing data; however, if you have missing data you could create the .def file and then edit to include missing values codes.
  4. You should include the formula.tools and stringr libaries
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/school23")

I will use as source the function

source("D:/Dropbox/edps587/lectures/8 modelbuilding/MIXREGLS/school23/R_mixregls.R")

Syntax

Most of the options are set to defaults but can easily be changed as will be illustrated below. Also all of these are described in Hekeke & Nordgren (2013)

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) 
# The data
indata <- read.table("nels23_data.txt", header=TRUE)

# A formula
fo <- formula(math ~ homew + sex + schtype | schtype | schtype  )

# Minimal input to run
R_mixregls(fo, indata, idname="school", 
     outdata="nels_example1.dat", 
     outresults="nels_example1.out", 
     save_def="nels_example1.def",
     NCOV=1)  
## [1] 0

Take A Look AT output

Models fit and parameter estimates

model_summaries<- readLines("nels_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]  nels_example1.dat                                                               
##  [11]  nels_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 =      519                                       
##  [24]                                                                                  
##  [25]  Number of level-2 clusters     =       23                                       
##  [26]                                                                                  
##  [27]  Number of level-1 observations for each level-2 cluster                         
##  [28]      44     8     5    24    23    17    22    20    24    20    22    22    20  
##  [29]      16    23    20    19    67    21    21    27    20    14                    
##  [30]                                                                                  
##  [31]  Dependent variable                                                              
##  [32]                  mean         min         max     std dev                        
##  [33]  --------------------------------------------------------                        
##  [34]  math         51.7225     30.0000     71.0000     10.7092                        
##  [35]                                                                                  
##  [36]  Mean model covariates                                                           
##  [37]                  mean         min         max     std dev                        
##  [38]  --------------------------------------------------------                        
##  [39]  homew         1.9711      0.0000      7.0000      1.4839                        
##  [40]   sex          1.5202      1.0000      2.0000      0.5001                        
##  [41]  schtype       1.9769      1.0000      4.0000      1.3281                        
##  [42]                                                                                  
##  [43]  BS variance model covariates                                                    
##  [44]                  mean         min         max     std dev                        
##  [45]  --------------------------------------------------------                        
##  [46]  schtype       1.9769      1.0000      4.0000      1.3281                        
##  [47]                                                                                  
##  [48]  WS variance model covariates                                                    
##  [49]                  mean         min         max     std dev                        
##  [50]  --------------------------------------------------------                        
##  [51]  schtype       1.9769      1.0000      4.0000      1.3281                        
##  [52]                                                                                  
##  [53]                                                                                  
##  [54] ---------------                                                                  
##  [55] Starting Values                                                                  
##  [56] ---------------                                                                  
##  [57]                                                                                  
##  [58]  BETA: mean model regression coefficients                                        
##  [59]    44.7379    2.3836   -0.8285    1.6463                                         
##  [60]                                                                                  
##  [61]  ALPHA: BS variance log-linear model regression coefficients                     
##  [62]     2.8037   -0.0246                                                             
##  [63]                                                                                  
##  [64]  TAU: WS variance log-linear model regression coefficients                       
##  [65]     4.2624   -0.0246                                                             
##  [66]                                                                                  
##  [67]  Random location (mean) effect on WS variance                                    
##  [68]     0.2004                                                                       
##  [69]  Scale standard deviation                                                        
##  [70]     0.4898                                                                       
##  [71]                                                                                  
##  [72]                                                                                  
##  [73] ------------------------------                                                   
##  [74] Model without Scale Parameters                                                   
##  [75] ------------------------------                                                   
##  [76]  Total  Iterations =   6                                                         
##  [77]  Final Ridge value = 0.0                                                         
##  [78]                                                                                  
##  [79]  Log Likelihood                 =    -1861.041                                   
##  [80]  Akaike's Information Criterion =    -1868.041                                   
##  [81]  Schwarz's Bayesian Criterion   =    -1872.016                                   
##  [82]                                                                                  
##  [83]  ==> multiplied by -2                                                            
##  [84]  Log Likelihood                 =     3722.083                                   
##  [85]  Akaike's Information Criterion =     3736.083                                   
##  [86]  Schwarz's Bayesian Criterion   =     3744.031                                   
##  [87]                                                                                  
##  [88]                                                                                  
##  [89]  Variable         Estimate     AsymStdError          z-value          p-value    
##  [90]  --------     ------------     ------------     ------------     ------------    
##  [91]  BETA (regression coefficients)                                                  
##  [92]  Intercpt         44.25150          2.02438         21.85926          0.00000    
##  [93]  homew             2.34615          0.27790          8.44248          0.00000    
##  [94]   sex             -0.74888          0.76390         -0.98034          0.32692    
##  [95]  schtype           1.93189          1.04046          1.85677          0.06334    
##  [96]  ALPHA (BS variance parameters: log-linear model)                                
##  [97]  Intercpt          1.66763          0.72173          2.31060          0.02086    
##  [98]  schtype           0.51767          0.29837          1.73502          0.08274    
##  [99]  TAU (WS variance parameters: log-linear model)                                  
## [100]  Intercpt          4.26256          0.06353         67.09843          0.00000    
## [101]                                                                                  
## [102]                                                                                  
## [103] ---------------------------                                                      
## [104] Model WITH Scale Parameters                                                      
## [105] ---------------------------                                                      
## [106]  Total  Iterations =   9                                                         
## [107]  Final Ridge value = 0.0                                                         
## [108]                                                                                  
## [109]  Log Likelihood                 =    -1855.254                                   
## [110]  Akaike's Information Criterion =    -1863.254                                   
## [111]  Schwarz's Bayesian Criterion   =    -1867.796                                   
## [112]                                                                                  
## [113]  ==> multiplied by -2                                                            
## [114]  Log Likelihood                 =     3710.508                                   
## [115]  Akaike's Information Criterion =     3726.508                                   
## [116]  Schwarz's Bayesian Criterion   =     3735.592                                   
## [117]                                                                                  
## [118]                                                                                  
## [119]  Variable         Estimate     AsymStdError          z-value          p-value    
## [120]  --------     ------------     ------------     ------------     ------------    
## [121]  BETA (regression coefficients)                                                  
## [122]  Intercpt         44.29881          2.01211         22.01605          0.00000    
## [123]  homew             2.24645          0.26278          8.54883          0.00000    
## [124]   sex             -0.71251          0.74706         -0.95375          0.34021    
## [125]  schtype           1.98936          1.04742          1.89930          0.05752    
## [126]  ALPHA (BS variance parameters: log-linear model)                                
## [127]  Intercpt          1.54097          0.76640          2.01065          0.04436    
## [128]  schtype           0.56214          0.30219          1.86024          0.06285    
## [129]  TAU (WS variance parameters: log-linear model)                                  
## [130]  Intercpt          4.57824          0.11570         39.56894          0.00000    
## [131]  schtype          -0.17045          0.04861         -3.50676          0.00045    
## [132]                                                                                  
## [133]                                                                                  
## [134] -----------------------                                                          
## [135] Model WITH RANDOM Scale                                                          
## [136] -----------------------                                                          
## [137]  Total  Iterations =  13                                                         
## [138]  Final Ridge value = 0.0                                                         
## [139]                                                                                  
## [140]  Log Likelihood                 =    -1854.457                                   
## [141]  Akaike's Information Criterion =    -1864.457                                   
## [142]  Schwarz's Bayesian Criterion   =    -1870.134                                   
## [143]                                                                                  
## [144]  ==> multiplied by -2                                                            
## [145]  Log Likelihood                 =     3708.913                                   
## [146]  Akaike's Information Criterion =     3728.913                                   
## [147]  Schwarz's Bayesian Criterion   =     3740.268                                   
## [148]                                                                                  
## [149]                                                                                  
## [150]  Variable         Estimate     AsymStdError          z-value          p-value    
## [151]  --------     ------------     ------------     ------------     ------------    
## [152]  BETA (regression coefficients)                                                  
## [153]  Intercpt         44.33596          2.01189         22.03697          0.00000    
## [154]  homew             2.22950          0.26997          8.25836          0.00000    
## [155]   sex             -0.70867          0.74354         -0.95310          0.34054    
## [156]  schtype           1.97860          1.04404          1.89515          0.05807    
## [157]  ALPHA (BS variance parameters: log-linear model)                                
## [158]  Intercpt          1.57915          0.76368          2.06781          0.03866    
## [159]  schtype           0.54966          0.29570          1.85884          0.06305    
## [160]  TAU (WS variance parameters: log-linear model)                                  
## [161]  Intercpt          4.58679          0.13137         34.91428          0.00000    
## [162]  schtype          -0.17742          0.05765         -3.07738          0.00209    
## [163]  Random location (mean) effect on WS variance                                    
## [164]  Loc  Eff          0.07342          0.08174          0.89821          0.36907    
## [165]  Random scale standard deviation                                                 
## [166]  Std Dev           0.14119          0.09240          1.52798          0.12652

Just the Numbers

readLines("MIXREGLS.EST")
##  [1] "    3722.082719       6     200"                                            
##  [2] "    44.25150073     2.34614536    -0.74887663     1.93188823"               
##  [3] "     1.66762733     0.51767392"                                             
##  [4] "     4.26255633"                                                            
##  [5] "     2.02438210     0.27789758     0.76389761     1.04045609     0.72172967"
##  [6] "     0.29836724     0.06352691"                                             
##  [7] "    3710.507994       9     200"                                            
##  [8] "    44.29880684     2.24645035    -0.71250645     1.98935823"               
##  [9] "     1.54096568     0.56214296"                                             
## [10] "     4.57823614    -0.17044857"                                             
## [11] "     2.01211389     0.26277875     0.74705607     1.04741550     0.76640313"
## [12] "     0.30218900     0.11570277     0.04860575"                              
## [13] "    3708.913495      13     200"                                            
## [14] "    44.33596474     2.22949542    -0.70866999     1.97860291"               
## [15] "     1.57915127     0.54965701"                                             
## [16] "     4.58678581    -0.17741618"                                             
## [17] "     0.07342047     0.14119008"                                             
## [18] "     2.01189045     0.26996814     0.74354133     1.04403687     0.76368377"
## [19] "     0.29569915     0.13137276     0.05765173     0.08174101     0.09240311"

Iteration history

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] "    1.095834627451376 8.275792265556330"            
##   [8] "   -2 Log-Likelihood =     3725.85087"              
##   [9] " Newton-Raphson Iteration     2 with ridge   0.0000"
##  [10] "   maximum correction and derivative"               
##  [11] "    7.693575178196128E-02 1.560921459705948"        
##  [12] "   -2 Log-Likelihood =     3722.15739"              
##  [13] " Newton-Raphson Iteration     3 with ridge   0.0000"
##  [14] "   maximum correction and derivative"               
##  [15] "    1.510219549719200E-02 6.288897786075243E-02"    
##  [16] "   -2 Log-Likelihood =     3722.08303"              
##  [17] " Newton-Raphson Iteration     4 with ridge   0.0000"
##  [18] "   maximum correction and derivative"               
##  [19] "    1.100064091041021E-04 3.813607024905075E-04"    
##  [20] "   -2 Log-Likelihood =     3722.08272"              
##  [21] " Newton-Raphson Iteration     5 with ridge   0.0000"
##  [22] "   maximum correction and derivative"               
##  [23] "    5.488873141206965E-09 1.876020139235379E-08"    
##  [24] "   -2 Log-Likelihood =     3722.08272"              
##  [25] "   maximum correction and derivative"               
##  [26] "    3.555400562735551E-12 6.905809257773399E-12"    
##  [27] "   -2 Log-Likelihood =     3722.08272"              
##  [28] " "                                                  
##  [29] "---------------------------"                        
##  [30] "Model WITH Scale Parameters"                        
##  [31] "---------------------------"                        
##  [32] " Newton-Raphson Iteration     1 with ridge   0.1000"
##  [33] "   maximum correction and derivative"               
##  [34] "    9.152074001000320E-02 37.82707410368207"        
##  [35] "   -2 Log-Likelihood =     3719.52618"              
##  [36] " Newton-Raphson Iteration     2 with ridge   0.1000"
##  [37] "   maximum correction and derivative"               
##  [38] "    6.872585251269775E-02 27.60429747166064"        
##  [39] "   -2 Log-Likelihood =     3715.01039"              
##  [40] " Newton-Raphson Iteration     3 with ridge   0.1000"
##  [41] "   maximum correction and derivative"               
##  [42] "    4.900772974775337E-02 19.24504975811226"        
##  [43] "   -2 Log-Likelihood =     3712.64954"              
##  [44] " Newton-Raphson Iteration     4 with ridge   0.1000"
##  [45] "   maximum correction and derivative"               
##  [46] "    3.386780001410764E-02 13.23455334693403"        
##  [47] "   -2 Log-Likelihood =     3711.50500"              
##  [48] " Newton-Raphson Iteration     5 with ridge   0.0000"
##  [49] "   maximum correction and derivative"               
##  [50] "    7.209622518538311E-02 9.066898920444936"        
##  [51] "   -2 Log-Likelihood =     3710.96966"              
##  [52] " Newton-Raphson Iteration     6 with ridge   0.0000"
##  [53] "   maximum correction and derivative"               
##  [54] "    2.145642321368735E-03 0.5644640517330801"       
##  [55] "   -2 Log-Likelihood =     3710.50825"              
##  [56] " Newton-Raphson Iteration     7 with ridge   0.0000"
##  [57] "   maximum correction and derivative"               
##  [58] "    1.942550391354983E-06 3.556557808477301E-04"    
##  [59] "   -2 Log-Likelihood =     3710.50799"              
##  [60] " Newton-Raphson Iteration     8 with ridge   0.0000"
##  [61] "   maximum correction and derivative"               
##  [62] "    2.104218659652576E-11 2.586666436599216E-10"    
##  [63] "   -2 Log-Likelihood =     3710.50799"              
##  [64] "   maximum correction and derivative"               
##  [65] "    1.697030701641697E-13 5.917488721252084E-13"    
##  [66] "   -2 Log-Likelihood =     3710.50799"              
##  [67] " "                                                  
##  [68] "-----------------------"                            
##  [69] "Model WITH RANDOM Scale"                            
##  [70] "-----------------------"                            
##  [71] " Newton-Raphson Iteration     1 with ridge   0.2000"
##  [72] "   maximum correction and derivative"               
##  [73] "    0.8030335520625563 20.23487348210596"           
##  [74] "   -2 Log-Likelihood =     3719.80949"              
##  [75] " Newton-Raphson Iteration     2 with ridge   0.2000"
##  [76] "   maximum correction and derivative"               
##  [77] "    5.229800167115933E-02 6.559366352024711"        
##  [78] "   -2 Log-Likelihood =     3709.80646"              
##  [79] " Newton-Raphson Iteration     3 with ridge   0.2000"
##  [80] "   maximum correction and derivative"               
##  [81] "    1.943389801601105E-02 4.236760491758237"        
##  [82] "   -2 Log-Likelihood =     3709.09295"              
##  [83] " Newton-Raphson Iteration     4 with ridge   0.2000"
##  [84] "   maximum correction and derivative"               
##  [85] "    1.278885592177282E-02 2.950716334282731"        
##  [86] "   -2 Log-Likelihood =     3708.99816"              
##  [87] " Newton-Raphson Iteration     5 with ridge   0.2000"
##  [88] "   maximum correction and derivative"               
##  [89] "    1.100376898095719E-02 2.117970339504217"        
##  [90] "   -2 Log-Likelihood =     3708.95583"              
##  [91] " Newton-Raphson Iteration     6 with ridge   0.2000"
##  [92] "   maximum correction and derivative"               
##  [93] "    9.334912009394465E-03 1.568084308415922"        
##  [94] "   -2 Log-Likelihood =     3708.93596"              
##  [95] " Newton-Raphson Iteration     7 with ridge   0.2000"
##  [96] "   maximum correction and derivative"               
##  [97] "    6.405304398932340E-03 0.8381090565351587"       
##  [98] "   -2 Log-Likelihood =     3708.91981"              
##  [99] " Newton-Raphson Iteration     8 with ridge   0.2000"
## [100] "   maximum correction and derivative"               
## [101] "    4.347093843429422E-03 0.5463029925584184"       
## [102] "   -2 Log-Likelihood =     3708.91622"              
## [103] " Newton-Raphson Iteration     9 with ridge   0.2000"
## [104] "   maximum correction and derivative"               
## [105] "    2.974613927236782E-03 0.3932119969612056"       
## [106] "   -2 Log-Likelihood =     3708.91490"              
## [107] " Newton-Raphson Iteration    10 with ridge   0.0000"
## [108] "   maximum correction and derivative"               
## [109] "    6.899216427513330E-03 0.2944344631448630"       
## [110] "   -2 Log-Likelihood =     3708.91427"              
## [111] " Newton-Raphson Iteration    11 with ridge   0.0000"
## [112] "   maximum correction and derivative"               
## [113] "    1.797344792833063E-05 1.058960327099956E-03"    
## [114] "   -2 Log-Likelihood =     3708.91350"              
## [115] " Newton-Raphson Iteration    12 with ridge   0.0000"
## [116] "   maximum correction and derivative"               
## [117] "    3.392125295744964E-09 4.565051081595328E-08"    
## [118] "   -2 Log-Likelihood =     3708.91350"              
## [119] "   maximum correction and derivative"               
## [120] "    7.338389002016553E-12 6.366963206660969E-11"    
## [121] "   -2 Log-Likelihood =     3708.91350"

Standardized Residuals Model 1 & Random Effects

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

Example 2

In this example, I will set some of the options, one of which I recomend that is to give meaingful titles that will appead in the output.

R_mixregls(fo, indata, idname="school", 
     outdata="nels_example1.dat", 
     outresults="nels_example1.out", 
     save_def="nels_example1.def",
     title1="NELS Example 1",
     title2="Illusration of adding titles")
## [1] 0
# Table of output
model_summaries<- readLines("nels_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]  NELS Example 1                                                                  
##   [7]  Illusration of adding titles                                                    
##   [8]                                                                                  
##   [9]  data and output files:                                                          
##  [10]  nels_example1.dat                                                               
##  [11]  nels_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 =      519                                       
##  [24]                                                                                  
##  [25]  Number of level-2 clusters     =       23                                       
##  [26]                                                                                  
##  [27]  Number of level-1 observations for each level-2 cluster                         
##  [28]      44     8     5    24    23    17    22    20    24    20    22    22    20  
##  [29]      16    23    20    19    67    21    21    27    20    14                    
##  [30]                                                                                  
##  [31]  Dependent variable                                                              
##  [32]                  mean         min         max     std dev                        
##  [33]  --------------------------------------------------------                        
##  [34]  math         51.7225     30.0000     71.0000     10.7092                        
##  [35]                                                                                  
##  [36]  Mean model covariates                                                           
##  [37]                  mean         min         max     std dev                        
##  [38]  --------------------------------------------------------                        
##  [39]  homew         1.9711      0.0000      7.0000      1.4839                        
##  [40]   sex          1.5202      1.0000      2.0000      0.5001                        
##  [41]  schtype       1.9769      1.0000      4.0000      1.3281                        
##  [42]                                                                                  
##  [43]  BS variance model covariates                                                    
##  [44]                  mean         min         max     std dev                        
##  [45]  --------------------------------------------------------                        
##  [46]  schtype       1.9769      1.0000      4.0000      1.3281                        
##  [47]                                                                                  
##  [48]  WS variance model covariates                                                    
##  [49]                  mean         min         max     std dev                        
##  [50]  --------------------------------------------------------                        
##  [51]  schtype       1.9769      1.0000      4.0000      1.3281                        
##  [52]                                                                                  
##  [53]                                                                                  
##  [54] ---------------                                                                  
##  [55] Starting Values                                                                  
##  [56] ---------------                                                                  
##  [57]                                                                                  
##  [58]  BETA: mean model regression coefficients                                        
##  [59]    44.7379    2.3836   -0.8285    1.6463                                         
##  [60]                                                                                  
##  [61]  ALPHA: BS variance log-linear model regression coefficients                     
##  [62]     2.8037   -0.0246                                                             
##  [63]                                                                                  
##  [64]  TAU: WS variance log-linear model regression coefficients                       
##  [65]     4.2624   -0.0246                                                             
##  [66]                                                                                  
##  [67]  Random location (mean) effect on WS variance                                    
##  [68]     0.2004                                                                       
##  [69]  Scale standard deviation                                                        
##  [70]     0.4898                                                                       
##  [71]                                                                                  
##  [72]                                                                                  
##  [73] ------------------------------                                                   
##  [74] Model without Scale Parameters                                                   
##  [75] ------------------------------                                                   
##  [76]  Total  Iterations =   6                                                         
##  [77]  Final Ridge value = 0.0                                                         
##  [78]                                                                                  
##  [79]  Log Likelihood                 =    -1861.041                                   
##  [80]  Akaike's Information Criterion =    -1868.041                                   
##  [81]  Schwarz's Bayesian Criterion   =    -1872.016                                   
##  [82]                                                                                  
##  [83]  ==> multiplied by -2                                                            
##  [84]  Log Likelihood                 =     3722.083                                   
##  [85]  Akaike's Information Criterion =     3736.083                                   
##  [86]  Schwarz's Bayesian Criterion   =     3744.031                                   
##  [87]                                                                                  
##  [88]                                                                                  
##  [89]  Variable         Estimate     AsymStdError          z-value          p-value    
##  [90]  --------     ------------     ------------     ------------     ------------    
##  [91]  BETA (regression coefficients)                                                  
##  [92]  Intercpt         44.25150          2.02438         21.85926          0.00000    
##  [93]  homew             2.34615          0.27790          8.44248          0.00000    
##  [94]   sex             -0.74888          0.76390         -0.98034          0.32692    
##  [95]  schtype           1.93189          1.04046          1.85677          0.06334    
##  [96]  ALPHA (BS variance parameters: log-linear model)                                
##  [97]  Intercpt          1.66763          0.72173          2.31060          0.02086    
##  [98]  schtype           0.51767          0.29837          1.73502          0.08274    
##  [99]  TAU (WS variance parameters: log-linear model)                                  
## [100]  Intercpt          4.26256          0.06353         67.09843          0.00000    
## [101]                                                                                  
## [102]                                                                                  
## [103] ---------------------------                                                      
## [104] Model WITH Scale Parameters                                                      
## [105] ---------------------------                                                      
## [106]  Total  Iterations =   9                                                         
## [107]  Final Ridge value = 0.0                                                         
## [108]                                                                                  
## [109]  Log Likelihood                 =    -1855.254                                   
## [110]  Akaike's Information Criterion =    -1863.254                                   
## [111]  Schwarz's Bayesian Criterion   =    -1867.796                                   
## [112]                                                                                  
## [113]  ==> multiplied by -2                                                            
## [114]  Log Likelihood                 =     3710.508                                   
## [115]  Akaike's Information Criterion =     3726.508                                   
## [116]  Schwarz's Bayesian Criterion   =     3735.592                                   
## [117]                                                                                  
## [118]                                                                                  
## [119]  Variable         Estimate     AsymStdError          z-value          p-value    
## [120]  --------     ------------     ------------     ------------     ------------    
## [121]  BETA (regression coefficients)                                                  
## [122]  Intercpt         44.29881          2.01211         22.01605          0.00000    
## [123]  homew             2.24645          0.26278          8.54883          0.00000    
## [124]   sex             -0.71251          0.74706         -0.95375          0.34021    
## [125]  schtype           1.98936          1.04742          1.89930          0.05752    
## [126]  ALPHA (BS variance parameters: log-linear model)                                
## [127]  Intercpt          1.54097          0.76640          2.01065          0.04436    
## [128]  schtype           0.56214          0.30219          1.86024          0.06285    
## [129]  TAU (WS variance parameters: log-linear model)                                  
## [130]  Intercpt          4.57824          0.11570         39.56894          0.00000    
## [131]  schtype          -0.17045          0.04861         -3.50676          0.00045    
## [132]                                                                                  
## [133]                                                                                  
## [134] -----------------------                                                          
## [135] Model WITH RANDOM Scale                                                          
## [136] -----------------------                                                          
## [137]  Total  Iterations =  13                                                         
## [138]  Final Ridge value = 0.0                                                         
## [139]                                                                                  
## [140]  Log Likelihood                 =    -1854.457                                   
## [141]  Akaike's Information Criterion =    -1864.457                                   
## [142]  Schwarz's Bayesian Criterion   =    -1870.134                                   
## [143]                                                                                  
## [144]  ==> multiplied by -2                                                            
## [145]  Log Likelihood                 =     3708.913                                   
## [146]  Akaike's Information Criterion =     3728.913                                   
## [147]  Schwarz's Bayesian Criterion   =     3740.268                                   
## [148]                                                                                  
## [149]                                                                                  
## [150]  Variable         Estimate     AsymStdError          z-value          p-value    
## [151]  --------     ------------     ------------     ------------     ------------    
## [152]  BETA (regression coefficients)                                                  
## [153]  Intercpt         44.33596          2.01189         22.03697          0.00000    
## [154]  homew             2.22950          0.26997          8.25836          0.00000    
## [155]   sex             -0.70867          0.74354         -0.95310          0.34054    
## [156]  schtype           1.97860          1.04404          1.89515          0.05807    
## [157]  ALPHA (BS variance parameters: log-linear model)                                
## [158]  Intercpt          1.57915          0.76368          2.06781          0.03866    
## [159]  schtype           0.54966          0.29570          1.85884          0.06305    
## [160]  TAU (WS variance parameters: log-linear model)                                  
## [161]  Intercpt          4.58679          0.13137         34.91428          0.00000    
## [162]  schtype          -0.17742          0.05765         -3.07738          0.00209    
## [163]  Random location (mean) effect on WS variance                                    
## [164]  Loc  Eff          0.07342          0.08174          0.89821          0.36907    
## [165]  Random scale standard deviation                                                 
## [166]  Std Dev           0.14119          0.09240          1.52798          0.12652

A more Complex model

This is a random intercept version of Model 5 from lecture notes.

schMses <- as.data.frame(aggregate(ses~school, data=indata, FUN="mean"))
names(schMses) <- c('school', 'schMses')
indata <- merge(indata,schMses, by=c('school'))
indata$schCses <- indata$ses - indata$schMses

This is similar to model 5 in lecture notes and Model_Building R example

fo <- formula(math ~ homew + sex + schCses + schMses + schtype  | schtype  | schtype )
R_mixregls(fo, indata, idname="school", 
     outdata="nels_complex.dat", 
     outresults="nels_complex.out", 
     save_def="nels_complex.def",
     title1="NELS Example 1",
     title2="Illusration of adding titles")
## [1] 0
# Table of output
model_summaries<- readLines("nels_complex.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]  NELS Example 1                                                                  
##   [7]  Illusration of adding titles                                                    
##   [8]                                                                                  
##   [9]  data and output files:                                                          
##  [10]  nels_complex.dat                                                                
##  [11]  nels_complex.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 =      519                                       
##  [24]                                                                                  
##  [25]  Number of level-2 clusters     =       23                                       
##  [26]                                                                                  
##  [27]  Number of level-1 observations for each level-2 cluster                         
##  [28]      44     8     5    24    23    17    22    20    24    20    22    22    20  
##  [29]      16    23    20    19    67    21    21    27    20    14                    
##  [30]                                                                                  
##  [31]  Dependent variable                                                              
##  [32]                  mean         min         max     std dev                        
##  [33]  --------------------------------------------------------                        
##  [34]  math         51.7225     30.0000     71.0000     10.7092                        
##  [35]                                                                                  
##  [36]  Mean model covariates                                                           
##  [37]                  mean         min         max     std dev                        
##  [38]  --------------------------------------------------------                        
##  [39]  homew         1.9711      0.0000      7.0000      1.4839                        
##  [40]   sex          1.5202      1.0000      2.0000      0.5001                        
##  [41]  schCses       0.0000     -1.9971      1.7290      0.6250                        
##  [42]     schMs     -0.0013     -1.0685      1.1763      0.6206                        
##  [43]  es    sc      1.9769      1.0000      4.0000      1.3281                        
##  [44]                                                                                  
##  [45]  BS variance model covariates                                                    
##  [46]                  mean         min         max     std dev                        
##  [47]  --------------------------------------------------------                        
##  [48]  schtype       1.9769      1.0000      4.0000      1.3281                        
##  [49]                                                                                  
##  [50]  WS variance model covariates                                                    
##  [51]                  mean         min         max     std dev                        
##  [52]  --------------------------------------------------------                        
##  [53]  schtype       1.9769      1.0000      4.0000      1.3281                        
##  [54]                                                                                  
##  [55]                                                                                  
##  [56] ---------------                                                                  
##  [57] Starting Values                                                                  
##  [58] ---------------                                                                  
##  [59]                                                                                  
##  [60]  BETA: mean model regression coefficients                                        
##  [61]    51.9841    2.1564   -0.6682    3.3185    9.1874   -1.8349                     
##  [62]                                                                                  
##  [63]  ALPHA: BS variance log-linear model regression coefficients                     
##  [64]     2.0175   -0.0642                                                             
##  [65]                                                                                  
##  [66]  TAU: WS variance log-linear model regression coefficients                       
##  [67]     4.2009   -0.0642                                                             
##  [68]                                                                                  
##  [69]  Random location (mean) effect on WS variance                                    
##  [70]     0.2004                                                                       
##  [71]  Scale standard deviation                                                        
##  [72]     0.4898                                                                       
##  [73]                                                                                  
##  [74]                                                                                  
##  [75] ------------------------------                                                   
##  [76] Model without Scale Parameters                                                   
##  [77] ------------------------------                                                   
##  [78]  Total  Iterations =   7                                                         
##  [79]  Final Ridge value = 0.0                                                         
##  [80]                                                                                  
##  [81]  Log Likelihood                 =    -1838.395                                   
##  [82]  Akaike's Information Criterion =    -1847.395                                   
##  [83]  Schwarz's Bayesian Criterion   =    -1852.504                                   
##  [84]                                                                                  
##  [85]  ==> multiplied by -2                                                            
##  [86]  Log Likelihood                 =     3676.789                                   
##  [87]  Akaike's Information Criterion =     3694.789                                   
##  [88]  Schwarz's Bayesian Criterion   =     3705.009                                   
##  [89]                                                                                  
##  [90]                                                                                  
##  [91]  Variable         Estimate     AsymStdError          z-value          p-value    
##  [92]  --------     ------------     ------------     ------------     ------------    
##  [93]  BETA (regression coefficients)                                                  
##  [94]  Intercpt         50.31060          2.38227         21.11874          0.00000    
##  [95]  homew             2.09594          0.27073          7.74180          0.00000    
##  [96]   sex             -0.50543          0.73996         -0.68305          0.49458    
##  [97]  schCses           3.33994          0.57843          5.77410          0.00000    
##  [98]     schMs          8.27633          1.94452          4.25624          0.00002    
##  [99]  es    sc         -0.87835          1.22395         -0.71763          0.47298    
## [100]  ALPHA (BS variance parameters: log-linear model)                                
## [101]  Intercpt          0.27658          1.08312          0.25536          0.79845    
## [102]  schtype           0.80865          0.43119          1.87540          0.06074    
## [103]  TAU (WS variance parameters: log-linear model)                                  
## [104]  Intercpt          4.19789          0.06344         66.16875          0.00000    
## [105]                                                                                  
## [106]                                                                                  
## [107] ---------------------------                                                      
## [108] Model WITH Scale Parameters                                                      
## [109] ---------------------------                                                      
## [110]  Total  Iterations =   9                                                         
## [111]  Final Ridge value = 0.0                                                         
## [112]                                                                                  
## [113]  Log Likelihood                 =    -1834.466                                   
## [114]  Akaike's Information Criterion =    -1844.466                                   
## [115]  Schwarz's Bayesian Criterion   =    -1850.144                                   
## [116]                                                                                  
## [117]  ==> multiplied by -2                                                            
## [118]  Log Likelihood                 =     3668.933                                   
## [119]  Akaike's Information Criterion =     3688.933                                   
## [120]  Schwarz's Bayesian Criterion   =     3700.288                                   
## [121]                                                                                  
## [122]                                                                                  
## [123]  Variable         Estimate     AsymStdError          z-value          p-value    
## [124]  --------     ------------     ------------     ------------     ------------    
## [125]  BETA (regression coefficients)                                                  
## [126]  Intercpt         50.17732          2.39892         20.91664          0.00000    
## [127]  homew             2.06480          0.25794          8.00509          0.00000    
## [128]   sex             -0.47739          0.72904         -0.65482          0.51258    
## [129]  schCses           3.17400          0.58292          5.44502          0.00000    
## [130]     schMs          8.19304          1.96733          4.16456          0.00003    
## [131]  es    sc         -0.76985          1.24651         -0.61760          0.53684    
## [132]  ALPHA (BS variance parameters: log-linear model)                                
## [133]  Intercpt          0.12962          1.15725          0.11201          0.91082    
## [134]  schtype           0.86771          0.44266          1.96022          0.04997    
## [135]  TAU (WS variance parameters: log-linear model)                                  
## [136]  Intercpt          4.45617          0.11453         38.90860          0.00000    
## [137]  schtype          -0.13854          0.04825         -2.87140          0.00409    
## [138]                                                                                  
## [139]                                                                                  
## [140] -----------------------                                                          
## [141] Model WITH RANDOM Scale                                                          
## [142] -----------------------                                                          
## [143]  Total  Iterations =  13                                                         
## [144]  Final Ridge value = 0.0                                                         
## [145]                                                                                  
## [146]  Log Likelihood                 =    -1834.007                                   
## [147]  Akaike's Information Criterion =    -1846.007                                   
## [148]  Schwarz's Bayesian Criterion   =    -1852.820                                   
## [149]                                                                                  
## [150]  ==> multiplied by -2                                                            
## [151]  Log Likelihood                 =     3668.014                                   
## [152]  Akaike's Information Criterion =     3692.014                                   
## [153]  Schwarz's Bayesian Criterion   =     3705.640                                   
## [154]                                                                                  
## [155]                                                                                  
## [156]  Variable         Estimate     AsymStdError          z-value          p-value    
## [157]  --------     ------------     ------------     ------------     ------------    
## [158]  BETA (regression coefficients)                                                  
## [159]  Intercpt         50.10698          2.39753         20.89946          0.00000    
## [160]  homew             2.07714          0.26496          7.83943          0.00000    
## [161]   sex             -0.49451          0.72641         -0.68076          0.49602    
## [162]  schCses           3.18663          0.58071          5.48751          0.00000    
## [163]     schMs          7.97654          2.00020          3.98786          0.00007    
## [164]  es    sc         -0.75606          1.23118         -0.61410          0.53915    
## [165]  ALPHA (BS variance parameters: log-linear model)                                
## [166]  Intercpt          0.19162          1.15420          0.16602          0.86814    
## [167]  schtype           0.83273          0.43945          1.89496          0.05810    
## [168]  TAU (WS variance parameters: log-linear model)                                  
## [169]  Intercpt          4.46252          0.12808         34.84275          0.00000    
## [170]  schtype          -0.14433          0.05635         -2.56152          0.01042    
## [171]  Random location (mean) effect on WS variance                                    
## [172]  Loc  Eff          0.04180          0.09847          0.42451          0.67119    
## [173]  Random scale standard deviation                                                 
## [174]  Std Dev           0.13677          0.09672          1.41412          0.15733

Setting BS to none

A formula

fo <- formula(math ~ homew + sex + schtype | none | schtype  )

R_mixregls(fo, indata, idname="school", 
     outdata="nels_no_bs.dat", 
     outresults="nels_no_bs.out", 
     save_def="nels_no_bs.def",
     title1="Model without BS predictors of Variance",
     title2="NELS data with 23 schools",
     NCOV=0)
## [1] 0
# Table of output
model_no_bs<- readLines("nels_no_bs.out")
noquote(model_no_bs)
##   [1] MIXREGLS: Mixed-effects Location Scale Model with BS and WS variance models      
##   [2]                                                                                  
##   [3] ---------------------------                                                      
##   [4] MIXREGLS.DEF specifications                                                      
##   [5] ---------------------------                                                      
##   [6]  Model without BS predictors of Variance                                         
##   [7]  NELS data with 23 schools                                                       
##   [8]                                                                                  
##   [9]  data and output files:                                                          
##  [10]  nels_no_bs.dat                                                                  
##  [11]  nels_no_bs.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 =      519                                       
##  [24]                                                                                  
##  [25]  Number of level-2 clusters     =       23                                       
##  [26]                                                                                  
##  [27]  Number of level-1 observations for each level-2 cluster                         
##  [28]      44     8     5    24    23    17    22    20    24    20    22    22    20  
##  [29]      16    23    20    19    67    21    21    27    20    14                    
##  [30]                                                                                  
##  [31]  Dependent variable                                                              
##  [32]                  mean         min         max     std dev                        
##  [33]  --------------------------------------------------------                        
##  [34]  math         51.7225     30.0000     71.0000     10.7092                        
##  [35]                                                                                  
##  [36]  Mean model covariates                                                           
##  [37]                  mean         min         max     std dev                        
##  [38]  --------------------------------------------------------                        
##  [39]  homew         1.9711      0.0000      7.0000      1.4839                        
##  [40]   sex          1.5202      1.0000      2.0000      0.5001                        
##  [41]  schtype       1.9769      1.0000      4.0000      1.3281                        
##  [42]                                                                                  
##  [43]  WS variance model covariates                                                    
##  [44]                  mean         min         max     std dev                        
##  [45]  --------------------------------------------------------                        
##  [46]                1.9769      1.0000      4.0000      1.3281                        
##  [47]                                                                                  
##  [48]                                                                                  
##  [49] ---------------                                                                  
##  [50] Starting Values                                                                  
##  [51] ---------------                                                                  
##  [52]                                                                                  
##  [53]  BETA: mean model regression coefficients                                        
##  [54]    44.7379    2.3836   -0.8285    1.6463                                         
##  [55]                                                                                  
##  [56]  ALPHA: BS variance log-linear model regression coefficients                     
##  [57]     2.8037                                                                       
##  [58]                                                                                  
##  [59]  TAU: WS variance log-linear model regression coefficients                       
##  [60]     4.2624   -0.0246                                                             
##  [61]                                                                                  
##  [62]  Scale standard deviation                                                        
##  [63]     0.4898                                                                       
##  [64]                                                                                  
##  [65]                                                                                  
##  [66] ------------------------------                                                   
##  [67] Model without Scale Parameters                                                   
##  [68] ------------------------------                                                   
##  [69]  Total  Iterations =   4                                                         
##  [70]  Final Ridge value = 0.0                                                         
##  [71]                                                                                  
##  [72]  Log Likelihood                 =    -1862.738                                   
##  [73]  Akaike's Information Criterion =    -1868.738                                   
##  [74]  Schwarz's Bayesian Criterion   =    -1872.145                                   
##  [75]                                                                                  
##  [76]  ==> multiplied by -2                                                            
##  [77]  Log Likelihood                 =     3725.477                                   
##  [78]  Akaike's Information Criterion =     3737.477                                   
##  [79]  Schwarz's Bayesian Criterion   =     3744.290                                   
##  [80]                                                                                  
##  [81]                                                                                  
##  [82]  Variable         Estimate     AsymStdError          z-value          p-value    
##  [83]  --------     ------------     ------------     ------------     ------------    
##  [84]  BETA (regression coefficients)                                                  
##  [85]  Intercpt         44.77335          2.06785         21.65210          0.00000    
##  [86]  homew             2.38312          0.27738          8.59160          0.00000    
##  [87]   sex             -0.82827          0.76213         -1.08678          0.27713    
##  [88]  schtype           1.61878          0.79299          2.04135          0.04122    
##  [89]  ALPHA (BS variance parameters: log-linear model)                                
##  [90]  Intercpt          2.80354          0.36397          7.70277          0.00000    
##  [91]  TAU (WS variance parameters: log-linear model)                                  
##  [92]  Intercpt          4.26242          0.06351         67.11092          0.00000    
##  [93]                                                                                  
##  [94]                                                                                  
##  [95] ---------------------------                                                      
##  [96] Model WITH Scale Parameters                                                      
##  [97] ---------------------------                                                      
##  [98]  Total  Iterations =   9                                                         
##  [99]  Final Ridge value = 0.0                                                         
## [100]                                                                                  
## [101]  Log Likelihood                 =    -1857.270                                   
## [102]  Akaike's Information Criterion =    -1864.270                                   
## [103]  Schwarz's Bayesian Criterion   =    -1868.245                                   
## [104]                                                                                  
## [105]  ==> multiplied by -2                                                            
## [106]  Log Likelihood                 =     3714.541                                   
## [107]  Akaike's Information Criterion =     3728.541                                   
## [108]  Schwarz's Bayesian Criterion   =     3736.489                                   
## [109]                                                                                  
## [110]                                                                                  
## [111]  Variable         Estimate     AsymStdError          z-value          p-value    
## [112]  --------     ------------     ------------     ------------     ------------    
## [113]  BETA (regression coefficients)                                                  
## [114]  Intercpt         44.90190          2.08913         21.49306          0.00000    
## [115]  homew             2.28393          0.26285          8.68924          0.00000    
## [116]   sex             -0.79404          0.74560         -1.06497          0.28689    
## [117]  schtype           1.62101          0.79884          2.02920          0.04244    
## [118]  ALPHA (BS variance parameters: log-linear model)                                
## [119]  Intercpt          2.84991          0.35481          8.03227          0.00000    
## [120]  TAU (WS variance parameters: log-linear model)                                  
## [121]  Intercpt          4.56816          0.11522         39.64722          0.00000    
## [122]                   -0.16600          0.04869         -3.40907          0.00065    
## [123]                                                                                  
## [124]                                                                                  
## [125] -----------------------                                                          
## [126] Model WITH RANDOM Scale                                                          
## [127] -----------------------                                                          
## [128]  Total  Iterations =  13                                                         
## [129]  Final Ridge value = 0.0                                                         
## [130]                                                                                  
## [131]  Log Likelihood                 =    -1856.952                                   
## [132]  Akaike's Information Criterion =    -1864.952                                   
## [133]  Schwarz's Bayesian Criterion   =    -1869.494                                   
## [134]                                                                                  
## [135]  ==> multiplied by -2                                                            
## [136]  Log Likelihood                 =     3713.904                                   
## [137]  Akaike's Information Criterion =     3729.904                                   
## [138]  Schwarz's Bayesian Criterion   =     3738.988                                   
## [139]                                                                                  
## [140]                                                                                  
## [141]  Variable         Estimate     AsymStdError          z-value          p-value    
## [142]  --------     ------------     ------------     ------------     ------------    
## [143]  BETA (regression coefficients)                                                  
## [144]  Intercpt         44.86839          2.08928         21.47553          0.00000    
## [145]  homew             2.26090          0.26831          8.42648          0.00000    
## [146]   sex             -0.74849          0.74368         -1.00646          0.31419    
## [147]  schtype           1.61813          0.80059          2.02118          0.04326    
## [148]  ALPHA (BS variance parameters: log-linear model)                                
## [149]  Intercpt          2.85334          0.35418          8.05624          0.00000    
## [150]  TAU (WS variance parameters: log-linear model)                                  
## [151]  Intercpt          4.57387          0.12625         36.22758          0.00000    
## [152]                   -0.16949          0.05528         -3.06595          0.00217    
## [153]  Random scale standard deviation                                                 
## [154]  Std Dev           0.12806          0.09838          1.30168          0.19303

Summary of Input to Function

Required input:

Options and their defaults are