-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlin_reg.R
More file actions
23 lines (18 loc) · 819 Bytes
/
lin_reg.R
File metadata and controls
23 lines (18 loc) · 819 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
###Example R file to practice
#Simulate some data
set.seed(1256) #Set seed
cage_movies = runif(n=20, min=1, max=30) #Number of Nicolas Cage movies made each year
slope = 4 #Parameter that describes how many drownings occur for each Nicolas Cage move made in one year
int = 50 #Number of pool drownings IF Nicolas Cage made 0 movies in one year (like that will ever happen)
error = rnorm(n=20, mean=0, sd=15)
drownings = int + slope * cage_movies + error #drownings predicted by number of Nick Cage movies in one year.
#Plot data, linear?
plot(drownings~cage_movies)
#Normality?
shapiro.test(drownings)
#Regression
cage_mod = lm(drownings~cage_movies)
summary(cage_mod)
#Check resids vs predicted
plot(resid(cage_mod)~predict(cage_mod))
abline(h=0)