forked from theofpa/datascience
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregressionmodels-quiz4.R
57 lines (48 loc) · 1.33 KB
/
regressionmodels-quiz4.R
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#Q1
library(MASS)
shuttle1<-shuttle
levels(shuttle1$use)[1]<-"1"
levels(shuttle1$use)[2]<-"0"
shuttle1$use<-as.numeric(as.character(shuttle1$use))
glm(formula = use ~ factor(wind), family = binomial(logit), data = shuttle1)
1/exp(0.03181)
#Q2
summary(logRegshuttle <- glm(use ~ wind,family="binomial", data=shuttle1))
glm(formula = use ~ factor(wind)+magn, family = binomial(logit), data = shuttle1)
1/exp(0.03201)
#Q3
LogiRegUseMinus<-glm((1-shuttle$use)~shuttle$wind,family="binomial")
glm(formula = 1-use ~ factor(wind), family = binomial(logit), data = shuttle1)
1-0.03181
#Q4
exp(coef(glm(count ~ as.factor(spray) - 1, family="poisson", InsectSprays)))
14.5/15.333
data(InsectSprays)
InsectSprays
pspray <- glm(InsectSprays$count ~ factor(InsectSprays$spray),family="Poisson")
pspray <- glm(InsectSprays$count ~ factor(InsectSprays$spray),family="poisson")
summary(pspray)
exp(2.659)
#Q5
y=c(1:10)
x=y-1+rnorm(10)/10
z=c(1:10)
z=z*2
summary(lm(y~x+offset(z)))
z=z*4
summary(lm(y~x+offset(z)))
z=z+5
summary(lm(y~x+offset(z)))
z=z+100
summary(lm(y~x+offset(z)))
z=z/10
summary(lm(y~x+offset(z)))
z=z+log(10)
summary(lm(y~x+offset(z)))
#Q6
x <- -5:5
y <- c(5.12, 3.93, 2.67, 1.87, 0.52, 0.08, 0.93, 2.05, 2.54, 3.87, 4.97)
plot(y ~ x)
d1 <- c(0, 0 ,0, 0, 0, 0, 1 , 1, 1 , 1 , 1)
d2 <- c(1, 1 ,1, 1, 1, 1, 0 , 0, 0, 0 , 0)
summary(lm(y ~ d1*x))