"Anova" 函数拒绝在 R Knitr 中编译?
"Anova" function refuses to compile in R Knitr?
我的全部代码 运行 非常好。当我尝试使用 Knitr 生成 PDF/HTML 时,我收到一条错误消息
Error in Anova(mod1, type = "III") : could not find function "Anova"
有什么不同的建议吗?
Relevant code:
library(lsmeans)
library(lme4)
df <- read.csv(file = "file.csv", header = TRUE)
library(lmerTest)
mod1 <- lm(Yield ~ Treatment + Block, data = df)
Anova(mod1, type = "III")
lsm <- lsmeans (mod1, "Treatment")
Full Error:
Loading required package: emmeans
The 'lsmeans' package is now basically a front end for 'emmeans'.
Users are encouraged to switch the rest of the way.
See help('transition') for more information, including how to
convert old 'lsmeans' objects and scripts to work with 'emmeans'.
Loading required package: Matrix
Attaching package: 'lmerTest'
The following object is masked from 'package:lme4':
lmer
The following object is masked from 'package:stats':
step
Quitting from lines 12-38 (df_test.Rmd)
Error in Anova(mod1, type = "III") : could not find function "Anova"
Calls: <Anonymous> ... handle -> withCallingHandlers -> withVisible -> eval -> eval
Execution halted
您必须添加 library(car)
。 Anova()
函数来自这个包!
library(car)
library(lsmeans)
library(lme4)
df <- read.csv(file = "file.csv", header = TRUE)
library(lmerTest)
mod1 <- lm(Yield ~ Treatment + Block, data = df)
Anova(mod1, type = "III")
lsm <- lsmeans (mod1, "Treatment")
mtcar 示例:
```{r mtcars}
library(lsmeans)
library(lme4)
library(car)
library(lmerTest)
mod1 <- lm(mpg ~ cyl, data = mtcars)
Anova(mod1, type = "III")
lsm <- lsmeans (mod1, "cyl")
```
给出:
> Anova(mod1, type = "III")
Anova Table (Type III tests)
Response: mpg
Sum Sq Df F value Pr(>F)
(Intercept) 3430 1 333.7 < 2e-16 ***
cyl 818 1 79.6 6.1e-10 ***
Residuals 308 30
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> lsm <- lsmeans (mod1, "cyl")
> lsm
cyl lsmean SE df lower.CL upper.CL
6.19 20.1 0.567 30 18.9 21.2
Confidence level used: 0.95
我的全部代码 运行 非常好。当我尝试使用 Knitr 生成 PDF/HTML 时,我收到一条错误消息
Error in Anova(mod1, type = "III") : could not find function "Anova"
有什么不同的建议吗?
Relevant code:
library(lsmeans)
library(lme4)
df <- read.csv(file = "file.csv", header = TRUE)
library(lmerTest)
mod1 <- lm(Yield ~ Treatment + Block, data = df)
Anova(mod1, type = "III")
lsm <- lsmeans (mod1, "Treatment")
Full Error:
Loading required package: emmeans
The 'lsmeans' package is now basically a front end for 'emmeans'.
Users are encouraged to switch the rest of the way.
See help('transition') for more information, including how to
convert old 'lsmeans' objects and scripts to work with 'emmeans'.
Loading required package: Matrix
Attaching package: 'lmerTest'
The following object is masked from 'package:lme4':
lmer
The following object is masked from 'package:stats':
step
Quitting from lines 12-38 (df_test.Rmd)
Error in Anova(mod1, type = "III") : could not find function "Anova"
Calls: <Anonymous> ... handle -> withCallingHandlers -> withVisible -> eval -> eval
Execution halted
您必须添加 library(car)
。 Anova()
函数来自这个包!
library(car)
library(lsmeans)
library(lme4)
df <- read.csv(file = "file.csv", header = TRUE)
library(lmerTest)
mod1 <- lm(Yield ~ Treatment + Block, data = df)
Anova(mod1, type = "III")
lsm <- lsmeans (mod1, "Treatment")
mtcar 示例:
```{r mtcars}
library(lsmeans)
library(lme4)
library(car)
library(lmerTest)
mod1 <- lm(mpg ~ cyl, data = mtcars)
Anova(mod1, type = "III")
lsm <- lsmeans (mod1, "cyl")
```
给出:
> Anova(mod1, type = "III")
Anova Table (Type III tests)
Response: mpg
Sum Sq Df F value Pr(>F)
(Intercept) 3430 1 333.7 < 2e-16 ***
cyl 818 1 79.6 6.1e-10 ***
Residuals 308 30
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> lsm <- lsmeans (mod1, "cyl")
> lsm
cyl lsmean SE df lower.CL upper.CL
6.19 20.1 0.567 30 18.9 21.2
Confidence level used: 0.95