简体   繁体   中英

ANOVA Error: $ operator is invalid for atomic vectors

I'm using this code to run an ANOVA using type II SS, when the error gets thrown Error: $ operator is invalid for atomic vectors

library(tidyverse)
programmers <- read_table("http://tofu.byu.edu/stat230/programmers.txt")

programmers$LargeSystemExp <- 
  as_factor(programmers$LargeSystemExp)

programmers$YearsOfExp <-
  as_factor(programmers$YearsOfExp)

prog.lm <- lm(TimePredictionError ~ LargeSystemExp + YearsOfExp + LargeSystemExp:YearsOfExp, data=programmers)

anova(prog.lm)

anova(prog.lm,type=2)

How can I run the last line of code without error?

For type 2 ANOVA, use car::Anova will work.

car::Anova(prog.lm, type = 2)

Anova Table (Type II tests)

Response: TimePredictionError
                          Sum Sq Df F value    Pr(>F)    
LargeSystemExp             34504  1  358.59 2.469e-13 ***
YearsOfExp                 41720  2  216.79 2.540e-13 ***
LargeSystemExp:YearsOfExp  24234  2  125.93 2.614e-11 ***
Residuals                   1732 18                      
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM