[R] Problems using allEffects() (package effect)
Jonas Mandel
jonas.mandel at curie.fr
Fri Jun 18 11:10:14 CEST 2010
I have no error when fitting the model. The summary and anova seems to
be fine :
> summary(lm1)
Call:
lm(formula = Volume ~ temps + Traitement:temps + Série, data = data)
Residuals:
Min 1Q Median 3Q Max
-34.3134 -14.9527 -0.9835 12.9174 49.5546
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 24.827 5.128 4.841 4.93e-06 ***
temps -3.786 3.057 -1.239 0.2185
Série8 11.680 5.203 2.245 0.0271 *
temps:Traitement 3.162 1.277 2.477 0.0150 *
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 18.86 on 96 degrees of freedom
Multiple R-squared: 0.08465, Adjusted R-squared: 0.05604
F-statistic: 2.959 on 3 and 96 DF, p-value: 0.03617
> anova(lm1)
Analysis of Variance Table
Response: Volume
Df Sum Sq Mean Sq F value Pr(>F)
temps 1 762 762.09 2.1417 0.14661
Série 1 214 214.18 0.6019 0.43976
temps:Traitement 1 2183 2182.74 6.1340 0.01501 *
Residuals 96 34161 355.84
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
But the data is not at all balanced :
> table(data$Série, data$Traitemen)
1 2 3
7 0 28 31
8 24 17 0
In batch 7 there is no mouse treated with treatment 1, and in batch 8
there is no mouse treated with treatment 3. Maybe the error come from
here, even if lm() is fine with this ?
Cheers,
Jonas
Joris Meys a écrit :
> Could you then at least give the summary of the lm? It's really
> impossible to tell where your problem is without any information about
> the fit. It's a strange error, I never had it in this context, and
> this kind of errors often indicate that what goes in is wrong. Your
> lm() object is not well formed, so the problem should come from the
> fit itself. And as I can't see any obvious errors in your model
> formula, it has to be a problem with your data. Did you get no warning
> at all when fitting the model?
>
> Cheers
> Joris
>
> On Fri, Jun 18, 2010 at 10:19 AM, Jonas Mandel <jonas.mandel at curie.fr> wrote:
>> Hello,
>>
>> Sorry for the lack of clarity, I thought I was clear about the package :
>> it's the function allEffects from the package effects.
>>
>> Here is my example again (unfortunately I can't give the data) :
>> The data concerns effects of 3 treatments on the tumoral volume of mice.
>>
>>> head(data)
>> Id Série Traitement vTum temps Volume
>> 55656.1 55656 7 3 1 1 14.03
>> 55805.1 55805 7 3 3 1 59.92
>> 55829.1 55829 7 3 1 1 15.31
>> 55806.1 55806 7 3 2 1 28.01
>> 50725.1 50725 7 3 2 1 34.48
>> 55737.1 55737 7 3 2 1 43.56
>>
>> vTum is a factor coding for the qualitative initial volume, from small
>> to big, temps is the time (integer) in month since beginning of
>> treatment, and Série is a factor coding for the batch. Data is unbalanced.
>>
>> I fit a linear model as follows:
>>> lm1=lm(Volume ~ temps + Traitement:temps + Série , data)
>> And then I try to use allEffects to compute (and then plot) the effects
>> of the interaction:
>>> eff.lm1 <- allEffects(mod=lm1, xlevels=list(temps=c(1:3), Traitement=1:3))
>> And here is the error I get:
>> Error in apply(mod.matrix[, components], 1, prod) : index out of range
>>
>> In the example given in the help page there are factor variables and
>> numeric variables so I don't think the problem comes from here. Any help
>> is welcome here.
>>
>> Cheers,
>> Jonas
>>
>>
>> Joris Meys a écrit :
>>> Please, read the posting guide:
>>> - provide a minimal example
>>> - tell us from which package the function is coming
>>>
>>> I guess you used the function allEffects() from the package effects, and did :
>>> eff.lm1 <- allEffect(lm1)
>>>
>>> Then I guess that there's something wrong with the variables you put
>>> into the model. Sure they're factor variables and not numeric?
>>>
>>> Cheers
>>> Joris
>>>
>>>
>>>
>>> On Thu, Jun 17, 2010 at 6:03 PM, Jonas Mandel <jonas.mandel at curie.fr> wrote:
>>>> Dear R users,
>>>>
>>>> I have some trouble using the allEffects() function to compute and
>>>> display effect plots for a linear model.
>>>> My data is quite simple, it concerns effects of 3 treatments on the
>>>> tumoral volume of mice. vTum codes for the qualitative initial volume,
>>>> from small to big, temps is the time in month since beginning of
>>>> treatment, and Série codes for the batch. Data is unbalanced.
>>>>
>>>>> head(data)
>>>> Id Série Traitement vTum temps Volume
>>>> 55656.1 55656 7 3 1 1 14.03
>>>> 55805.1 55805 7 3 3 1 59.92
>>>> 55829.1 55829 7 3 1 1 15.31
>>>> 55806.1 55806 7 3 2 1 28.01
>>>> 50725.1 50725 7 3 2 1 34.48
>>>> 55737.1 55737 7 3 2 1 43.56
>>>>
>>>>
>>>> The linear model is also quite simple :
>>>>> lm1=lm(Volume ~ temps + Traitement:temps + Série , data)
>>>> But when I try to use allEffects() I get this error:
>>>>> eff.lm1 <- allEffect(mod=lm1,
>>>> Error in apply(mod.matrix[, components], 1, prod) : index out of range
>>>>
>>>> I read the help and the example but I don't understand the reason why it
>>>> doesn't work. Can you help me ?
>>>> Thanks
>>>>
>>>>
>>>> --
>>>> Jonas Mandel
>>>>
>>>> ______________________________________________
>>>> 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.
>>>>
>>>
>>>
>
>
>
More information about the R-help
mailing list