Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require(ggplot2)
- dat <- iris
- dat_setosa <- dat[which(dat$Species=="setosa"),]
- dat_versicolor <- dat[which(dat$Species=="versicolor"),]
- dat_virginica <- dat[which(dat$Species=="virginica"),]
- ggplot(dat_setosa , aes(x=Petal.Length, y=Sepal.Length)) + geom_point()
- ggplot(dat_versicolor , aes(x=Petal.Length, y=Sepal.Length)) + geom_point()
- ggplot(dat_virginica , aes(x=Petal.Length, y=Sepal.Length)) + geom_point()
- dat_setosa_ols <- lm(data=dat_setosa, Petal.Length ~ Sepal.Length)
- dat_versicolor_ols <- lm(data=dat_versicolor, Petal.Length ~ Sepal.Length)
- dat_virginica_ols <- lm(data=dat_virginica, Petal.Length ~ Sepal.Length)
- # beta
- dat_setosa_beta <- as.numeric(dat_setosa_ols$coefficients[1])
- dat_versicolor_beta <- as.numeric(dat_versicolor_ols$coefficients[1])
- dat_virginica_beta <- as.numeric(dat_virginica_ols$coefficients[1])
- # r squared
- dat_setosa_r2 <- summary(dat_setosa_ols)$r.squared
- dat_versicolor_r2 <- summary(dat_versicolor_ols)$r.squared
- dat_virginica_r2 <- summary(dat_virginica_ols)$r.squared
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement