Advertisement
Guest User

Untitled

a guest
Aug 19th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. require(ggplot2)
  2.  
  3. dat <- iris
  4. dat_setosa <- dat[which(dat$Species=="setosa"),]
  5. dat_versicolor <- dat[which(dat$Species=="versicolor"),]
  6. dat_virginica <- dat[which(dat$Species=="virginica"),]
  7.  
  8. ggplot(dat_setosa , aes(x=Petal.Length, y=Sepal.Length)) + geom_point()
  9. ggplot(dat_versicolor , aes(x=Petal.Length, y=Sepal.Length)) + geom_point()
  10. ggplot(dat_virginica , aes(x=Petal.Length, y=Sepal.Length)) + geom_point()
  11.  
  12. dat_setosa_ols <- lm(data=dat_setosa, Petal.Length ~ Sepal.Length)
  13. dat_versicolor_ols <- lm(data=dat_versicolor, Petal.Length ~ Sepal.Length)
  14. dat_virginica_ols <- lm(data=dat_virginica, Petal.Length ~ Sepal.Length)
  15.  
  16. # beta
  17. dat_setosa_beta <- as.numeric(dat_setosa_ols$coefficients[1])
  18. dat_versicolor_beta <- as.numeric(dat_versicolor_ols$coefficients[1])
  19. dat_virginica_beta <- as.numeric(dat_virginica_ols$coefficients[1])
  20.  
  21. # r squared
  22. dat_setosa_r2 <- summary(dat_setosa_ols)$r.squared
  23. dat_versicolor_r2 <- summary(dat_versicolor_ols)$r.squared
  24. dat_virginica_r2 <- summary(dat_virginica_ols)$r.squared
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement