Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. iris$group <- as.factor(rep(c("a","b")))
  2. str(iris)
  3.  
  4. #model without interaction
  5. mod <- lm(Sepal.Length ~ Sepal.Width+Species+group, iris)
  6. summary(mod)
  7.  
  8. #model with interaction(Species*group)
  9. mod2 <- lm(Sepal.Length ~ Sepal.Width+Species*group, iris)
  10. summary(mod2)
  11.  
  12. #dummy variables for interaction
  13. int1 <- ifelse(iris$Species=="versicolor" & iris$group=="b", 1, 0)
  14. int2 <- ifelse(iris$Species=="virginica" & iris$group=="b", 1, 0)
  15.  
  16. #model with dummy variables
  17. mod3 <- lm(Sepal.Length ~ Sepal.Width+Species+group+int1+int2, iris)
  18. summary(mod3)
  19. summary(mod2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement