SHARE
TWEET

Untitled

a guest Mar 19th, 2019 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top