[R] Help with contrast settings in glm and lm
Jesús María Frías Celayeta
iosu at ensia.inra.fr
Fri Jan 14 12:14:21 CET 2000
Hi!
I am trying to validate some R code that we have been porting from
S (ellipse library) and now we are on the step of trying with some
examples to see if the code gives the same results as in S. I have
received some results from S-PLUS 4.5 help examples and I have some
trouble reproducing them. Apparently S+ uses helbert contrasts in
categorical variables as a default and R uses contrasts based in
orthogonal polynomials. However, in R there exists contr.helmert and I
would like to actually set R in a way that a regression procedure will use
helmert type contrasts (as in S+), in order to have the same results.
Is there a way to change the default contrasts used in regression
(lm and glm) so that after it the regression uses those contrasts? I have
tried options() with no too much sucess. I am probably loosing some page
in the manual, so just in the case I excuse myself in advance.
This is the detailed thing.
1.-My fit with cntr.poly (the default) is
> glmfit.R
Call: glm(formula = skips ~ ., family = poisson, data = solder.balance)
Coefficients:
(Intercept) Opening.L Opening.Q Solder.L MaskA3 MaskB3
-0.06267 -1.33890 0.56194 -0.77763 0.42819 1.20225
MaskB6 PadTypeD4 PadTypeL4 PadTypeD6 PadTypeL6 PadTypeD7
1.86648 0.11000 0.37237 -0.25865 -0.55845 0.01156
PadTypeL7 PadTypeL8 PadTypeW9 PadTypeL9 Panel2 Panel3
-0.38021 -0.16115 -1.32758 -0.52645 0.33352 0.25440
Degrees of Freedom: 719 Total (i.e. Null); 702 Residual
Null Deviance: 6856
Residual Deviance: 1130 AIC: 2749
2.-When I change the options for the contrasts for contr.helmert to try to
emulate S+ results.
> options(contrasts=c("contr.treatment", "contr.helmert"))
> glmfit.R.2<- glm(formula = skips ~ ., family = poisson, data =
solder.balance)
> glmfit.R.2
Call: glm(formula = skips ~ ., family = poisson, data = solder.balance)
Coefficients:
(Intercept) Opening1 Opening2 Solder1 MaskA3 MaskB3
-0.06267 -0.81749 -0.35867 -0.54987 0.42819 1.20225
MaskB6 PadTypeD4 PadTypeL4 PadTypeD6 PadTypeL6 PadTypeD7
1.86648 0.11000 0.37237 -0.25865 -0.55845 0.01156
PadTypeL7 PadTypeL8 PadTypeW9 PadTypeL9 Panel2 Panel3
-0.38021 -0.16115 -1.32758 -0.52645 0.33352 0.25440
Degrees of Freedom: 719 Total (i.e. Null); 702 Residual
Null Deviance: 6856
Residual Deviance: 1130 AIC: 2749
> options("contrasts")
$contrasts
[1] "contr.treatment" "contr.helmert"
which is the same as in 1
3.- This result does quite differ from the glm in S+ using helmert
contrasts:
> glmfit
Call:
glm(formula = skips ~ ., family = poisson, data = solder.balance)
Coefficients:
(Intercept) Opening.L Opening.Q Solder Mask1 Mask2 Mask3 PadType1 PadType2
0.7356797 -1.338898 0.5619403 -0.7776274 0.2140968 0.3293834 0.3307507 0.05500044 0.1057882
PadType3 PadType4 PadType5 PadType6 PadType7 PadType8 PadType9 Panel1
-0.1048597 -0.1228765 0.01308473 -0.04662037 -0.007583584 -0.1355021 -0.02828819 0.1667612
Panel2
0.02921374
Degrees of Freedom: 720 Total; 702 Residual
Residual Deviance: 1130.48
Thanks in advance for any help,
IOsu
-------------------------------------------------------------------------------
Jesús María Frías Celayeta "Valeu a pena? Tudo vale a pena
ENSIA-INRA, Av. des Olympiades, 1 se a alma não é pequena
91744, Massy. FRANCE Quem quer passar além do Bojador
Fax:intl+33+1+69935185 Tem que passar além da dor.
Phone:intl+33+1+69935191 Deus ao mar o perigo e abismo deu,
Mas nele é que espelhou o céu"
-------------------------------------------------------------------------------
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list