extracting covariance between coefficients

Welcome to the forum for R2MLwiN users. Feel free to post your question about R2MLwiN here. The Centre for Multilevel Modelling take no responsibility for the accuracy of these posts, we are unable to monitor them closely. Do go ahead and post your question and thank you in advance if you find the time to post any answers!

Go to R2MLwiN: Running MLwiN from within R >> http://www.bris.ac.uk/cmm/software/r2mlwin/
Post Reply
MannyGomez
Posts: 17
Joined: Mon Feb 17, 2014 4:55 pm

extracting covariance between coefficients

Post by MannyGomez »

Dear Richard,
After estimating an hierarchical model using R2MLwiN, is there a way of directly extracting the covariance between two estimated (fixed) coefficients?
I am looking into the object from runMLwiN, say 'estimates' ----> estimates["estIGLS"]
and check the 2nd column (_FP_v) which I think contains all the variances and covariances of the (fixed) coefficient parameters. However, if one has many coefficients it becomes quite tricky to tell which one is which.

Is there another way of extracting the covariances, or do we really need to extract it from this column?

Many thanks,
Manny

ChrisCharlton
Posts: 1193
Joined: Mon Oct 19, 2009 10:34 am

Re: extracting covariance between coefficients

Post by ChrisCharlton »

This information is available in the FP.cov attribute of the model object. The example below demonstrates how to extract it:

Code: Select all

> library(R2MLwiN)
Loading required package: lattice
Loading required package: coda
Loading required package: foreign
Loading required package: rbugs
> mydata <- read.dta("http://www.bristol.ac.uk/cmm/media/runmlwin/tutorial.dta")
> (mymodel <- runMLwiN(normexam~(0|cons+standlrt+girl)+(1|cons), "student", indata=mydata, MLwiNPath="C:/Program Files (x86)/MLwiN v2.30/"))
ECHO    0

Execution completed

-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- 
MLwiN multilevel model (Normal) 
Estimation algorithm:  IGLS        Elapsed time : 0.22s 
Number of obs:  4059 (from total 4059 )
Deviance statistic:  9717 
--------------------------------------------------------------------------------------------------- 
The model formula:
normexam ~ (0 | cons + standlrt + girl) + (1 | cons)
Level 1: student      
--------------------------------------------------------------------------------------------------- 
The fixed part estimates:  
              Coef.   Std. Err.       z    Pr(>|z|)         [95% Conf.   Interval] 
cons       -0.10318     0.01990   -5.19    2.15e-07   ***     -0.14218    -0.06419 
standlrt    0.59060     0.01268   46.59           0   ***      0.56575     0.61544 
girl        0.16996     0.02570    6.61   3.758e-11   ***      0.11959     0.22033 
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1  
--------------------------------------------------------------------------------------------------- 
The random part estimates at the student level: 
             Coef.   Std. Err. 
var_cons   0.64151     0.01424 
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
# Extract the fixed-part covariance matrix (lower diagonal):
> mymodel@FP.cov
                  FP_cons   FP_standlrt      FP_girl
FP_cons      3.958961e-04            NA           NA
FP_standlrt  1.011306e-05  1.607037e-04           NA
FP_girl     -3.963507e-04 -1.733569e-05 0.0006604741
# Confirm that this corresponds with the reported standard errors:
> sqrt(diag(mymodel@FP.cov))
    FP_cons FP_standlrt     FP_girl 
 0.01989714  0.01267690  0.02569969

MannyGomez
Posts: 17
Joined: Mon Feb 17, 2014 4:55 pm

Re: extracting covariance between coefficients

Post by MannyGomez »

Thanks Chris!
Apologies for having missed the FP.cov component included in the object. :oops:

Post Reply