Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong printing of lme4 objects #565

Closed
GillesSanMartin opened this issue Jul 4, 2013 · 3 comments
Closed

Wrong printing of lme4 objects #565

GillesSanMartin opened this issue Jul 4, 2013 · 3 comments
Labels
bug Bugs
Milestone

Comments

@GillesSanMartin
Copy link

Hello

I have encountered a very strange behavior of knitr that appears only in very specific conditions. It seems that there is something wrong with the internal knit from spin function.

Consider the following R script example :

library(lme4)
m <- lmer(Reaction ~ Days + (Days|Subject), sleepstudy)
summary(m)
print(m, cor=FALSE)

If I use spin("myscript.R", report=FALSE) I obtain 2 files : myscript.md and myscript.Rmd.

The md file does not print correctly the results :

m <- lmer(Reaction ~ Days + (Days | Subject), sleepstudy)
summary(m)
## Length  Class   Mode 
##      1    mer     S4
print(m, cor = FALSE)
## <S4 Type Object>
## attr(,"env")
## <environment: 0x8f89a80>
## attr(,"nlmodel")
## I(x)
## attr(,"frame")
##     Reaction Days Subject
## 1      249.6    0     308
## 2      258.7    1     308
## 3      250.8    2     308
## 4      321.4    3     308
## 5      356.9    4     308
## 6      414.7    5     308
## 7      382.2    6     308
## 8      290.1    7     308

etc... ( 1000+ additionnal lines)

But if I knit the Rmd file generated by spin knit("myscript.Rmd"), the resulting md file is correct :

library(lme4)
m <- lmer(Reaction ~ Days + (Days | Subject), sleepstudy)
summary(m)
## Linear mixed model fit by REML 
## Formula: Reaction ~ Days + (Days | Subject) 
##    Data: sleepstudy 
##   AIC  BIC logLik deviance REMLdev
##  1756 1775   -872     1752    1744
## Random effects:
##  Groups   Name        Variance Std.Dev. Corr  
##  Subject  (Intercept) 612.1    24.74          
##           Days         35.1     5.92    0.066 
##  Residual             654.9    25.59          
## Number of obs: 180, groups: Subject, 18
## 
## Fixed effects:
##             Estimate Std. Error t value
## (Intercept)   251.41       6.82    36.8
## Days           10.47       1.55     6.8
## 
## Correlation of Fixed Effects:
##      (Intr)
## Days -0.138
print(m, cor = FALSE)
## Linear mixed model fit by REML 
## Formula: Reaction ~ Days + (Days | Subject) 
##    Data: sleepstudy 
##   AIC  BIC logLik deviance REMLdev
##  1756 1775   -872     1752    1744
## Random effects:
##  Groups   Name        Variance Std.Dev. Corr  
##  Subject  (Intercept) 612.1    24.74          
##           Days         35.1     5.92    0.066 
##  Residual             654.9    25.59          
## Number of obs: 180, groups: Subject, 18
## 
## Fixed effects:
##             Estimate Std. Error t value
## (Intercept)   251.41       6.82    36.8
## Days           10.47       1.55     6.8

if I use print(m) instead of print(m, cor = FALSE), the output fo this part is correct.
And if I use the compile HTML notebook button from Rstudio(0.97.332) using spin the output is correct too.
Really strange...

> sessionInfo()
R version 3.0.1 (2013-05-16)
Platform: x86_64-pc-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=fr_BE.UTF-8       LC_NUMERIC=C               LC_TIME=fr_BE.UTF-8       
 [4] LC_COLLATE=fr_BE.UTF-8     LC_MONETARY=fr_BE.UTF-8    LC_MESSAGES=fr_BE.UTF-8   
 [7] LC_PAPER=C                 LC_NAME=C                  LC_ADDRESS=C              
[10] LC_TELEPHONE=C             LC_MEASUREMENT=fr_BE.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] lme4_0.999999-2 Matrix_1.0-12   lattice_0.20-15 knitr_1.2      

loaded via a namespace (and not attached):
[1] digest_0.6.3   evaluate_0.4.3 formatR_0.7    grid_3.0.1     markdown_0.5.4 nlme_3.1-109  
[7] stats4_3.0.1   stringr_0.6.2  tools_3.0.1  
@yihui yihui closed this as completed in aa1b702 Jul 5, 2013
@yihui
Copy link
Owner

yihui commented Jul 5, 2013

It is an environment issue. I have fixed it now. Thanks for the report!

@GillesSanMartin
Copy link
Author

Great ! Thanks to you for developing these wonders !

@github-actions
Copy link

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Bugs
Projects
None yet
Development

No branches or pull requests

2 participants