-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRegression example 1.R
More file actions
29 lines (17 loc) · 921 Bytes
/
Copy pathRegression example 1.R
File metadata and controls
29 lines (17 loc) · 921 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#######################################################################
# Linear Regression
#######################################################################
install.packages("ggplot2", dependencies = TRUE)
library(ggplot)
download.file("http://bit.ly/PaceData", destfile="p.txt",method="curl", extra="-L")
dat<- read.csv("p.txt", header=T)
head(dat)
ggplot(dat, aes(y=speed, x=pop)) + geom_point()
linear.fit <- lm(speed ~ pop, data=dat)
summary(linear.fit)
P1 <- ggplot(dat, aes(y=speed, x=pop)) + geom_point() + scale_y_continuous(limits=c(0,3)) + geom_abline(intercept = coef(linear.fit)[1], slope = coef(linear.fit)[2], color='red')
P1
log.fit <- lm(log(speed) ~ log(pop), data=dat)
summary(log.fit)
p2 <- ggplot(dat, aes(y=log(speed), x=log(pop))) + geom_point() + geom_abline(intercept = coef(log.fit)[1], slope = coef(log.fit)[2], color='red')
p2