WEN Songqiao wrote:
Hi, everyone
I want to do simulation with R, how can I extract the estimate
"0.9005372 1.1191585 2.0367914" and "0.9957503 0.9231837" from
the following fitted model and put them into a null vector a?
thanks,
WEN Songqiao
----------------------------------------------------------------------------------------------------------------------------------------------
Linear mixed-effects model fit by REML
Data: data1
Log-restricted-likelihood: -478.909
Fixed: yij ~ xi1 + xi2
(Intercept) xi1 xi2
0.9005372 1.1191585 2.0367914
Random effects:
Formula: ~+1 | subject
(Intercept) Residual
StdDev: 0.9957503 0.9231837
Number of Observations: 300
Number of Groups: 100
----------------------------------------------------------------------------------------------------------------------------------------
R? Do you mean S-PLUS since you've sent your comments to S-News? If you
really mean R, then use the posting guide:
http://www.R-project.org/posting-guide.html
and resubmit your question to R-help. I think my answers are the same in
either case, but it's best to keep the questions for R on R-help and the
questions for S-PLUS on S-News.
Use ?fixef to get the fixed effects and my "extract.stdev" function
below to get the random effects:
> # From ?lme
> fm2 <- lme(distance ~ age + Sex, data=Orthodont, random = ~ 1)
> fm2
Linear mixed-effects model fit by REML
Data: Orthodont
Log-restricted-likelihood: -218.7563
Fixed: distance ~ age + Sex
(Intercept) age Sex
17.70671 0.6601852 -2.321023
Random effects:
Formula: ~ 1 | Subject
(Intercept) Residual
StdDev: 1.807425 1.431592
Number of Observations: 108
Number of Groups: 27
> fixef(fm2)
(Intercept) age Sex
17.70671 0.6601852 -2.321023
> extract.stdev
function(object)
{
struct <- object$modelStruct$reStruct
sigma <- object$sigma
Var <- rev(sapply(struct, as.matrix))
labels <- sapply(seq(Var), function(x, names)
paste(rev(names[1:x]), collapse = " %in% "), names = names(Var))
Sdev <- c(sqrt(Var) * sigma, sigma)
names(Sdev) <- c(labels, "Residual")
Sdev
}
> extract.stdev(fm2)
Subject Residual
1.807425 1.431592
>
|