Page 1 of 1
extracting covariance between coefficients
Posted: Wed Apr 02, 2014 8:17 pm
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
Re: extracting covariance between coefficients
Posted: Sat Apr 05, 2014 9:16 pm
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
Re: extracting covariance between coefficients
Posted: Sat Apr 05, 2014 9:56 pm
by MannyGomez
Thanks Chris!
Apologies for having missed the FP.cov component included in the object.
