Exam 3 (submit by Dec 1, 11:59 pm EST on Classes as a single PDF file) Instruction: This is the third of the 4 exams in BMB 620. Complete the following questions in RMarkdown and submitted the...

1 answer below »

View more »
Answered Same DayDec 02, 2021

Answer To: Exam 3 (submit by Dec 1, 11:59 pm EST on Classes as a single PDF file) Instruction: This is the...

Subhanbasha answered on Dec 02 2021
122 Votes
Exam3
Catherine
December 2021
knitr::opts_chunk$set(echo = TRUE,warning = FALSE,messages=FALSE)
Question 1.a
library(tinytex)
# Reading file
leuk <- read.table('leukemiaremission.txt',header = TRUE)

plot(REMISS~CELL,data=leuk,
main="Scatter Plot")
From the above scatter plot we can observe that CELL is incresed then it tends to
leukemia remission has occurred.
Question 1.b
# Logistic model
logi <- glm(REMISS~.,data=leuk)

# Summary of the model
summary(logi)
##
## Call:
## glm(formula = REMISS ~ ., data = leuk)
##
## D
eviance Residuals:
## Min 1Q Median 3Q Max
## -0.73148 -0.28640 0.01317 0.28326 0.61075
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 5.001776 6.717355 0.745 0.4652
## CELL -0.222161 1.779991 -0.125 0.9019
## SMEAR -1.528849 3.387515 -0.451 0.6566
## INFIL 1.584228 3.850919 0.411 0.6852
## LI 0.535005 0.266740 2.006 0.0586 .
## BLAST -0.009178 0.335354 -0.027 0.9784
## TEMP -4.949192 6.692905 -0.739 0.4682
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for gaussian family taken to be 0.1953698)
##
## Null deviance: 6.0000 on 26 degrees of freedom
## Residual deviance: 3.9074 on 20 degrees of freedom
## AIC: 40.433
##
## Number of Fisher Scoring iterations: 2
By observing the logistic regression model summary the p value of each independent
variable is greater than 0.05 so we can infer that non of the variables are significant in
the model.
Question 1.c
logit2prob <- function(logit){
odds <- exp(logit)
prob <- odds / (1 + odds)
return(prob)
}
logit2prob(coef(logi))
## (Intercept) CELL SMEAR INFIL LI BLAST
## 0.993318947 0.444687136 0.178162226 0.829802429 0.630649643 0.497705515
## TEMP
## 0.007039233
The variable INFIL has high probability than other variables that means it has hih
valuable in the model
Question 1.d
New_data<-data.frame(CELL=0.7,SMEAR=0.6,INFIL=0.8,LI=0.5,BLAST=0.6,TEMP=0.7)
predict(logi,newdata = New_data)
## 1
## 1.993898
Question 1.e
logi1 <- glm(REMISS~INFIL+LI+BLAST+CELL,data=leuk)
# Summary of the model
summary(logi1)
##
## Call:
## glm(formula = REMISS ~ INFIL + LI + BLAST + CELL, data = leuk)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -0.83660 -0.23042 -0.06619 0.23535 0.65026
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.60229 0.45452 -1.325 0.1987
## INFIL 0.05614 0.56418 0.100 0.9216
## LI 0.54888 0.22975 2.389 0.0259 *
## BLAST -0.05043 0.26502 -0.190 0.8508
## CELL 0.43947 0.56918 0.772 0.4483
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for gaussian family taken to be 0.1849362)
##
## Null deviance: 6.0000 on 26 degrees of freedom
## Residual deviance: 4.0686 on 22 degrees of freedom
## AIC: 37.524
##
## Number of Fisher Scoring iterations: 2
Comparing with the intial model the LI variable is significant in this model. Tha AIC
value is 37.524.
Question 1.f
plot(logi)
Question 2.a
library(lubridate)
##
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
##
## date, intersect, setdiff, union
civi <- read.csv('civilinjury0.csv')
unique(year(civi$Injury.Date))
## [1] 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016
unique(month(civi$Injury.Date))
## [1] 1 2 4 5 7 8 9 10 11 12 3 6
Question 2.b
civi$year <- year(civi$Injury.Date)
civi$mon <- month(civi$Injury.Date)
agg <- aggregate(civi["Total.Injuries"], by=civi[c("year","mon")],FUN=sum)
agg
## year mon Total.Injuries
## 1 2005 1 11
## 2 2006 1 2
## 3 2007 1 2
## 4 2008 1 4
## 5 2009 1 6
## 6 2010 1 1
## 7 2011 1 4
## 8 2012 1 9
## 9 2013 1 2
## 10 2014 1 1
## 11 2015 1 5
## 12 2005 2 3
## 13 2006 2 3
## 14 2007 2 7
## 15 2009 2 2
## 16 2010 2 1
## 17 2011 2 3
## 18 2012 2 3
## 19 2013 2 5
## 20 2014 2 2
## 21 2015 2 2
## 22 2006 3 4
## 23 2007 3 1
## 24 2008 3 2
## 25 2009 3 1
## 26 2010 3 1
## 27 2011 3 1
## 28 2012 3 4
## 29 2013 3 1
## 30 2014 3 2
## 31 2015 3 1
## 32 2016 3 1
## 33 2005 4 3
## 34 2006 4 7
## 35 2007 4 1
## 36 2008 4 3
## 37 2010 4 7
## 38 2011 4 3
## 39 2013 4 1
## 40 2015 4 1
## 41 2005 5 2
## 42 2006 5 3
## 43 2007 5 3
## 44 2008 5 2
## 45 2009 5 5
## 46 2010 5 7
## 47 2011 5 1
## 48 2012 5 1
## 49 2013 ...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here
April
January
February
March
April
May
June
July
August
September
October
November
December
2025
2025
2026
2027
SunMonTueWedThuFriSat
30
31
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
1
2
3
00:00
00:30
01:00
01:30
02:00
02:30
03:00
03:30
04:00
04:30
05:00
05:30
06:00
06:30
07:00
07:30
08:00
08:30
09:00
09:30
10:00
10:30
11:00
11:30
12:00
12:30
13:00
13:30
14:00
14:30
15:00
15:30
16:00
16:30
17:00
17:30
18:00
18:30
19:00
19:30
20:00
20:30
21:00
21:30
22:00
22:30
23:00
23:30