Marylin Bejarano
2011-Aug-17 21:40 UTC
[R] contrast package with interactions in gls model
Hi!
I try to explain the efffect of (1) forest where i took samples's soils (*
Lugar*: categorical variable with three levels), (2) nitrogen addition
treatments (*Tra*: categorical variable with two levels) on total carbon
concentration's soil samples (*C: *continue* *variable) during four months
of sampling (*Time:* categorical and ordered variable with four levels).
I fitted the following final model with gls function:
var1<-varIdent(form=~ 1| Lugar* factor(Time))
FINAL<-gls(C ~ Tra+ Lugar+ Time + Time*Tra + Tra*Lugar, data=datos,
weights=var1, method="REML")
the summary function resulted in this first data's set (I omit
correlation's
matrix):
Generalized least squares fit by REML
Model: C ~ Tra + Lugar + Time + Time * Tra + Tra * Lugar
Data: datos
AIC BIC logLik
1129.458 1191.982 -540.7291
Variance function:
Structure: Different standard deviations per stratum
Formula: ~1 | Lugar * factor(Time)
Parameter estimates:
Chixchulub*0 Xmatkuil*0 Hobonil*0 Chixchulub*2 Xmatkuil*2
Hobonil*2 Chixchulub*3
1.0000000 0.7759324 0.5300811 0.9640559 0.8200742
0.2966545 0.9553168
Xmatkuil*3 Hobonil*3 Chixchulub*4 Xmatkuil*4 Hobonil*4
1.7350290 0.3430286 0.6241658 0.9573922 0.4651515
Coefficients:
Value Std.Error t-value
p-value
(Intercept) 260.48540 16.48991 15.796653 0.0000
Tra0 -9.38703 23.74893 -0.395261 0.6935
LugarChixchulub -0.15377 19.60260 -0.007845 0.9938
Lugar Hobonil -173.21354 15.89736 -10.895741 0.0000
Time2 -14.74999 14.55909 -1.013112 0.3135
Time3 14.42177 15.64594 0.921758 0.3589
Time4 14.77803 16.72367 0.883659 0.3790
Tra0:Time2 17.93859 20.78257 0.863156 0.3901
Tra0:Time3 -48.77118 22.17628 -2.199250 0.0302
Tra0:Time4 -52.63611 23.20192 -2.268610 0.0254
Tra0:LugarChixchulub 74.43956 28.11275 2.647893 0.0094
Tra0:Lugar Hobonil 43.03416 23.32391 1.845066 0.0680
anova function generated this table:
enom. DF: 100
numDF F-value p-value
(Intercept) 1 1693.1234 <.0001
Tra 1 5.3225 0.0231
Lugar 2 247.7047 <.0001
Time 3 0.4767 0.6992
Tra:Time 3 6.0531 0.0008
Tra:Lugar 2 3.5061 0.0338
I want to detetect differences between levels of Tra:Lugar interaction. For
example:
1. Tra0:LugarChixchulub vs Tra1:LugarChixchulub (between treatment levels
for same forest) or,
2. Tra0:LugarChixchulub vs Tra0:LugarHobonil (for same treatment
among forests levels)
I used function contrast (package contrast) whit following script to probe
the hypotesis 1.:
con<-contrast(FINAL, list(Lugar= 'Xmatkuil', Tra=1),
list(Lugar='Xmatkuil',
Tra = 0))
but i found this error message:
Error en gendata.default(fit = list(modelStruct = list(varStruct
c(-0.253689933940456, :
not enough factors
I would be grateful if somebody tell me I'm doing wrong with my contrast
function script.
Thanks in advance,
Marylin Bejarano
PHd candidate in Ecology Institute of Mexico's National Autonomous
University
[[alternative HTML version deleted]]
You did not follow the posting guide. You did not specify which packages you were using. It appears that you are mixing the rms package with some other functions such as gls. If you want to use rms, use the Gls function instead of gls, and type ?contrast.rms to see examples of the use of contrast(). Frank Marylin Bejarano wrote:> > Hi! > > I try to explain the efffect of (1) forest where i took samples's soils > (* > Lugar*: categorical variable with three levels), (2) nitrogen addition > treatments (*Tra*: categorical variable with two levels) on total carbon > concentration's soil samples (*C: *continue* *variable) during four months > of sampling (*Time:* categorical and ordered variable with four levels). > > I fitted the following final model with gls function: > > var1<-varIdent(form=~ 1| Lugar* factor(Time)) > FINAL<-gls(C ~ Tra+ Lugar+ Time + Time*Tra + Tra*Lugar, data=datos, > weights=var1, method="REML") > > the summary function resulted in this first data's set (I omit > correlation's > matrix): > > Generalized least squares fit by REML > Model: C ~ Tra + Lugar + Time + Time * Tra + Tra * Lugar > Data: datos > AIC BIC logLik > 1129.458 1191.982 -540.7291 > > Variance function: > Structure: Different standard deviations per stratum > Formula: ~1 | Lugar * factor(Time) > Parameter estimates: > Chixchulub*0 Xmatkuil*0 Hobonil*0 Chixchulub*2 Xmatkuil*2 > Hobonil*2 Chixchulub*3 > 1.0000000 0.7759324 0.5300811 0.9640559 0.8200742 > 0.2966545 0.9553168 > Xmatkuil*3 Hobonil*3 Chixchulub*4 Xmatkuil*4 Hobonil*4 > 1.7350290 0.3430286 0.6241658 0.9573922 0.4651515 > > Coefficients: > Value Std.Error > t-value > p-value > (Intercept) 260.48540 16.48991 15.796653 0.0000 > Tra0 -9.38703 23.74893 -0.395261 0.6935 > LugarChixchulub -0.15377 19.60260 -0.007845 0.9938 > Lugar Hobonil -173.21354 15.89736 -10.895741 0.0000 > Time2 -14.74999 14.55909 -1.013112 0.3135 > Time3 14.42177 15.64594 0.921758 0.3589 > Time4 14.77803 16.72367 0.883659 0.3790 > Tra0:Time2 17.93859 20.78257 0.863156 0.3901 > Tra0:Time3 -48.77118 22.17628 -2.199250 0.0302 > Tra0:Time4 -52.63611 23.20192 -2.268610 0.0254 > Tra0:LugarChixchulub 74.43956 28.11275 2.647893 0.0094 > Tra0:Lugar Hobonil 43.03416 23.32391 1.845066 0.0680 > > anova function generated this table: > > enom. DF: 100 > numDF F-value p-value > (Intercept) 1 1693.1234 <.0001 > Tra 1 5.3225 0.0231 > Lugar 2 247.7047 <.0001 > Time 3 0.4767 0.6992 > Tra:Time 3 6.0531 0.0008 > Tra:Lugar 2 3.5061 0.0338 > > I want to detetect differences between levels of Tra:Lugar interaction. > For > example: > > 1. Tra0:LugarChixchulub vs Tra1:LugarChixchulub (between treatment levels > for same forest) or, > 2. Tra0:LugarChixchulub vs Tra0:LugarHobonil (for same treatment > among forests levels) > > I used function contrast (package contrast) whit following script to probe > the hypotesis 1.: > > con<-contrast(FINAL, list(Lugar= 'Xmatkuil', Tra=1), > list(Lugar='Xmatkuil', > Tra = 0)) > > but i found this error message: > > Error en gendata.default(fit = list(modelStruct = list(varStruct > c(-0.253689933940456, : > not enough factors > > I would be grateful if somebody tell me I'm doing wrong with my contrast > function script. > > Thanks in advance, > > > Marylin Bejarano > PHd candidate in Ecology Institute of Mexico's National Autonomous > University > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >----- Frank Harrell Department of Biostatistics, Vanderbilt University -- View this message in context: http://r.789695.n4.nabble.com/contrast-package-with-interactions-in-gls-model-tp3751255p3751269.html Sent from the R help mailing list archive at Nabble.com.