An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090401/5e0d023c/attachment-0001.pl>
Fit unequal variance model in R
9 messages · Feng, Jingyu, Dieter Menne, Feng Jingyu
Feng, Jingyu wrote:
I'am trying to develop some code if R, which would correspond to what I
did in SAS.
The data look like:
Treatment Replicate group1 GSI
..
The SAS code is:
proc mixed data=data_name order=data method=ml; *scoring=10;
classes group1;
model GSI=group1/residual influence solution;
repeated /group=group1;
run;
Basically, I need different variance for each treatment group. I want to
do the similar thing in R.
Here is what I get so far:
lm1<-lme(response~treatment,data=o,random=~1|as.factor(dummy),weights=varIdent(form=~1|treatment),method="ML")
There should no random term in the model. However If I don't specify one,
lme won't work, so I made a dummy variable, which equals to 1 for every
observation.
The much underused (quote Frank Harrell) gls in package nlme should do that. Quote PB (p250): It can be viewed as an lme function without the random argument. Dieter
View this message in context: http://www.nabble.com/Fit-unequal-variance-model-in-R-tp22829549p22830566.html Sent from the R help mailing list archive at Nabble.com.
2 days later
I used gls and it still does not provide me different estimates of variance
for each treatment group. Did I do anything wrong?
lm3<-gls(GSI~treatment,data=z,weights=varIdent(form=~treatment),method="ML")
summary(lm3)
Generalized least squares fit by maximum likelihood
Model: GSI ~ treatment
Data: z
AIC BIC logLik
9.174574 12.71483 0.4127128
Coefficients:
Value Std.Error t-value p-value
(Intercept) 1.0174923 0.1374462 7.402839 0.0000
treatmentHigh 0.7429293 0.1943783 3.822079 0.0028
treatmentLow -0.0146910 0.1943783 -0.075579 0.9411
treatmentMid 0.3869267 0.2099526 1.842924 0.0924
Correlation:
(Intr) trtmnH trtmnL
treatmentHigh -0.707
treatmentLow -0.707 0.500
treatmentMid -0.655 0.463 0.463
Standardized residuals:
Min Q1 Med Q3 Max
-1.9580366 -0.7219450 -0.1989222 0.9096203 1.8319336
Residual standard error: 0.2354039
Degrees of freedom: 15 total; 11 residual
Dieter Menne wrote:
Feng, Jingyu wrote:
I'am trying to develop some code if R, which would correspond to what I
did in SAS.
The data look like:
Treatment Replicate group1 GSI
..
The SAS code is:
proc mixed data=data_name order=data method=ml; *scoring=10;
classes group1;
model GSI=group1/residual influence solution;
repeated /group=group1;
run;
Basically, I need different variance for each treatment group. I want to
do the similar thing in R.
Here is what I get so far:
lm1<-lme(response~treatment,data=o,random=~1|as.factor(dummy),weights=varIdent(form=~1|treatment),method="ML")
There should no random term in the model. However If I don't specify one,
lme won't work, so I made a dummy variable, which equals to 1 for every
observation.
The much underused (quote Frank Harrell) gls in package nlme should do that. Quote PB (p250): It can be viewed as an lme function without the random argument. Dieter
View this message in context: http://www.nabble.com/Fit-unequal-variance-model-in-R-tp22829549p22873062.html Sent from the R help mailing list archive at Nabble.com.
Feng Jingyu wrote:
I used gls and it still does not provide me different estimates of variance for each treatment group. Did I do anything wrong? lm3<-gls(GSI~treatment,data=z,weights=varIdent(form=~treatment),method="ML")
try weights = varIdent(form~1|treatment) See the example in library/nlme/scripts/ch05.r ,fm1Orth.gls Dieter
View this message in context: http://www.nabble.com/Fit-unequal-variance-model-in-R-tp22829549p22873236.html Sent from the R help mailing list archive at Nabble.com.
Thanks a lot. The problem is solved. It took me a while to understand the output from the R. With little calculation, I am able to match results from R to SAS.
Dieter Menne wrote:
Feng Jingyu wrote:
I used gls and it still does not provide me different estimates of variance for each treatment group. Did I do anything wrong? lm3<-gls(GSI~treatment,data=z,weights=varIdent(form=~treatment),method="ML")
try weights = varIdent(form~1|treatment) See the example in library/nlme/scripts/ch05.r ,fm1Orth.gls Dieter
View this message in context: http://www.nabble.com/Fit-unequal-variance-model-in-R-tp22829549p22873995.html Sent from the R help mailing list archive at Nabble.com.
Feng Jingyu wrote:
Thanks a lot. The problem is solved. It took me a while to understand the output from the R. With little calculation, I am able to match results from R to SAS.
To conserve you sanity, don't try it. They will be different. Dieter
View this message in context: http://www.nabble.com/Fit-unequal-variance-model-in-R-tp22829549p22873997.html Sent from the R help mailing list archive at Nabble.com.
Hi For my purpose, I need to match variance estimates for each group from R and SAS. They do match now. I notice there are still some difference between those two. For example the standard errors of coeffieicints are different, but I don't care those.
Dieter Menne wrote:
To conserve you sanity, don't try it. They will be different. Dieter
View this message in context: http://www.nabble.com/Fit-unequal-variance-model-in-R-tp22829549p22874008.html Sent from the R help mailing list archive at Nabble.com.
Feng Jingyu wrote:
Hi For my purpose, I need to match variance estimates for each group from R and SAS. They do match now.
Consider yourself a lucky man! Dieter
View this message in context: http://www.nabble.com/Fit-unequal-variance-model-in-R-tp22829549p22874048.html Sent from the R help mailing list archive at Nabble.com.
Yes, I am considering I am a lucky man because you answered my question. Have a great weekend!
Dieter Menne wrote:
Feng Jingyu wrote:
Hi For my purpose, I need to match variance estimates for each group from R and SAS. They do match now.
Consider yourself a lucky man! Dieter
View this message in context: http://www.nabble.com/Fit-unequal-variance-model-in-R-tp22829549p22877276.html Sent from the R help mailing list archive at Nabble.com.