[R-sig-ME] [FORGED] Re: Export several lme outputs to a single excel file
Rolf Turner
r@turner @end|ng |rom @uck|@nd@@c@nz
Tue Oct 8 11:07:49 CEST 2019
On 8/10/19 9:28 PM, Mario Garrido wrote:
> Dear Emmanuel Curis,
> your approach was working perfectly, but at some point w gives me the
> error. when introduced the new column
> I have no problem in running model, the errors appears when introducing
> extra $Md column. I wonder whether the problem is the * of the
> significance, but is not, also is not due to character strings since my
> variables are recognized as factors. I have no missing data in my
> matrix,... And, as I said, problem only arise when I introduced the new
> column
>
> Thanks in advanxe
>> anova(TempLight_StdzDiff_3trt_earlypeak)-> r15
>> r15
> Analysis of Variance Table
>
> Response: StdzDiff
> Df Sum Sq Mean Sq F value Pr(>F)
> Trtmnt 2 0.991 0.4953 0.2382 0.78891
> sp 2 13.781 6.8904 3.3134 0.04407 *
> Trtmnt:sp 4 4.123 1.0306 0.4956 0.73898
> Residuals 53 110.217 2.0796
> ---
> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
>> r15$Md<- "TempLight_StdzDiff_3trt_earlypeak"
>> r15
> Analysis of Variance Table
>
> Response: StdzDiff
> Df Sum Sq Mean Sq F value Pr(>F) Md
> Trtmnt 2 0.991 0.4953 0.2382 0.78891
> sp 2 13.781 6.8904 3.3134 0.04407
> Trtmnt:sp 4 4.123 1.0306 0.4956 0.73898
> Residuals 53 110.217 2.0796
> Warning message:
> In data.matrix(x) : NAs introducidos por coerción
This is a "generic" problem; it is not peculiar to your model nor to
models fitted using lme, or other mixed modelling software.
Consider the following example:
set.seed(42)
x <- 1:20
y <- rnorm(20)
fit <- lm(y ~ x)
m <- anova(fit)
m$newColumn <- "yeeeeks"
m
This produces:
> Analysis of Variance Table
>
> Response: y
> Df Sum Sq Mean Sq F value Pr(>F) newColumn
> x 1 4.113 4.1130 2.5865 0.12518
> Residuals 18 28.624 1.5902
> Warning message:
> In data.matrix(x) : NAs introduced by coercion
The "reason" is that m is (in the first instance) of class "anova" and
there are (not unreasonably) certain restrictions as to how you can
treat an object of this class.
A work-around to get something like what you appear to want could be:
set.seed(42)
x <- 1:20
y <- rnorm(20)
fit <- lm(y ~ x)
m <- anova(fit)
m <- cbind(m,newColumn=c("yeeeks",rep("",nrow(m)-1)))
m
However m is now of class "data.frame" whence it is printed by the
method print.data.frame() rather than print.anova(). Consequently NAs
show up in the output of the print method:
Df Sum Sq Mean Sq F value Pr(>F) newColumn
x 1 0.04176282 0.04176282 0.03784897 0.8479256 yeeeks
Residuals 18 19.86132473 1.10340693 NA NA
You could just live with those NAs, or you could convert the "F value"
and "Pr(>F)" columns from numeric to character mode and replace the NAs
by null strings "".
HTH
cheers,
Rolf Turner
--
Honorary Research Fellow
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276
More information about the R-sig-mixed-models
mailing list