[R] lm - interaction factors - same number of items per level in factors?

Ista Zahn izahn at psych.rochester.edu
Tue Mar 8 18:10:32 CET 2011


Hi,
You should avoid entering interaction terms without also including the
lower-order terms involved in the interaction. Also, you are mixing
variables from the workspace with those in (the data.frame?) df, which
is a very bad idea. Try something like

mod.lm <- lm(res ~ var1+ var2 + var3 + fact1*fact2, data=dat)

Best,
Ista

On Tue, Mar 8, 2011 at 5:19 AM, agent dunham <crosspide at hotmail.com> wrote:
> Dear community,
>
> Apologies for my questions, I´m pretty newbie.
>
> The thing is, I was trying this lm:
>
> mod.lm <- lm(df$res ~ df$var1+ df$var2 + df$var3 +fact1:fact2)
>
> And factors are like this:
>
>> table(fact1)
>  a  b  c
>  3 90 83
>> table(fact2)
>  a  b  c
>  4 87 85
>
> Because of the interaction, i obtain the following error, (I guess...):
>
>> summary(mod.lm)
>
> Residuals:
>    Min      1Q  Median      3Q     Max
> -3.0163 -1.1604 -0.1741  0.9281  3.8957
>
> Coefficients: (3 not defined because of singularities)
>                         Estimate Std. Error t value Pr(>|t|)
> (Intercept)             6.5282000  0.7912553   8.250 4.64e-14 ***
> df$var1  0.0005589  0.0003627   1.541   0.1252
> df$var2   -0.2057033  0.0314158  -6.548 6.99e-10 ***
> df$var3       0.0565537  0.0273348   2.069   0.0401 *
> fact1a:fact2a          NA         NA      NA       NA
> fact1b:fact2a  -0.0086776  1.1375463  -0.008   0.9939
> fact15c:fact2a   0.7215114  1.6043880   0.450   0.6535
> fact1a:fact2b  -1.3091987  0.8251966  -1.587   0.1145
> fact1b:fact2b   0.2389941  0.3690889   0.648   0.5182
> fact1c:fact2b   0.5016906  0.3474390   1.444   0.1506
> fact1a:fact2c          NA         NA      NA       NA
> fact1b:fact2c   0.3121082  0.3491911   0.894   0.3727
> fact1c:fact2c          NA         NA      NA       NA
> ---
> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
>
> Residual standard error: 1.562 on 166 degrees of freedom
> Multiple R-squared: 0.3526,     Adjusted R-squared: 0.3175
> F-statistic: 10.04 on 9 and 166 DF,  p-value: 2.952e-12
>
> Should a, b, and c in the factors have the same number of entries?
>
> Thanks, user at host.com
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/lm-interaction-factors-same-number-of-items-per-level-in-factors-tp3341016p3341016.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.
>



-- 
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.org



More information about the R-help mailing list