[R] question about contrast in R for multi-factor linear regression models?
Mark Difford
mark_difford at yahoo.co.uk
Mon Nov 10 10:48:05 CET 2008
Hi losemind,
>> I understand the resultant "lm" coefficients for one factors, but when it
>> comes to the
>> interaction term, I got confused.
Yes, it is possible to lose your mind on this (so perhaps get a real name).
A good friend here is
?dummy.coef
In your case (i.e. treatment contrasts), your reference level for the
interaction terms are the reference levels of the factors themselves. In
your example, these seem to be A1 and b1. Assuming they are, the coefficient
for, say, dd$AA3:dd$Bb2 is worked out relative to them.
It also helps to have more descriptive names for your factors and factor
levels. This is why I haven't worked out what yours might be. In a busy day,
yours seem to be a nightmare.
HTH, Mark.
losemind wrote:
>
> Hi all,
>
> I am using "lm" to fit some anova factor models with interactions.
>
> The default setting for my unordered factors is "treatment". I
> understand the resultant "lm" coefficients for one factors, but when
> it comes to the interaction term, I got confused.
>
>> options()$contrasts
> unordered ordered
> "contr.treatment" "contr.poly"
>
> Here is my question:
>
> Factor A has 6 levels, B has 2 levels,
>
>> levels(dd$A)=c("A1", "A2", "A3", "A4", "A5", "A6")
>> levels(dd$B)=c("b1", "b2")
>
>
> My question is how to interpret the resultant coefficients. What are
> the bases of "dd$AA2:dd$Bb2" and "dd$AA3:dd$Bb2", etc. ?
>
> I am having a hard time to understand the result and making sense out
> of the numbers...
>
> Please help me ! Thank you!
>
>> zz=lm(formula = (dd$Y) ~ dd$A * dd$B)
>> summary(zz)
>
> Call:
> lm(formula = dd$Y~ dd$A * dd$B)
>
> Residuals:
> Min 1Q Median 3Q Max
> -1.68582 -0.42469 -0.02536 0.20012 3.50798
>
> Coefficients:
> Estimate Std. Error t value Pr(>|t|)
> (Intercept) 4.40842 0.40295 10.940 5.34e-13 ***
> dd$AA2 0.11575 0.56986 0.203 0.8402
> dd$AA3 0.01312 0.56986 0.023 0.9818
> dd$AA4 -0.06675 0.56986 -0.117 0.9074
> dd$AA5 0.10635 0.56986 0.187 0.8530
> dd$AA6 0.11507 0.56986 0.202 0.8411
> dd$Bb2 -0.58881 0.56986 -1.033 0.3084
> c 0.26465 0.80590 0.328 0.7445
> dd$AA3:dd$Bb2 0.40984 0.80590 0.509 0.6142
> dd$AA4:dd$Bb2 -0.02918 0.80590 -0.036 0.9713
> dd$AA5:dd$Bb2 0.35574 0.80590 0.441 0.6616
> dd$AA6:dd$Bb2 1.55424 0.80590 1.929 0.0617 .
> ---
> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
>
> Residual standard error: 0.8059 on 36 degrees of freedom
> Multiple R-squared: 0.2642, Adjusted R-squared: 0.03934
> F-statistic: 1.175 on 11 and 36 DF, p-value: 0.3378
>
> ______________________________________________
> 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.
>
>
--
View this message in context: http://www.nabble.com/question-about-contrast-in-R-for-multi-factor-linear-regression-models--tp20413510p20416877.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list