R語言代做編程輔導和解答GLM Coursework
全文鏈接:http://tecdat.cn/?p=30821
Twenty tobacco budworm moths of each sex were exposed to different doses of the insecticide trans-cypermethrin. The numbers of budworm moths killed during a 3-day exposure were as follows for each sex (male, female) and dose level in mg’s
num.killed sex dose ?1 1 male 1 ?2 4 male 2 ?3 9 male 4 ?4 13 male 8 ?5 18 male 16 ?6 20 male 32 ?7 0 female 1 ?8 2 female 2 ?9 6 female 4 ?10 10 female 8 ?11 12 female 16 ?12 16 female 32
Type the data into R as follows. Press Enter at the end of each line including blank lines.
num.killed <- scan() ?1 4 9 13 18 20 0 2 6 10 12 16 ?sex <- scan() ?0 0 0 0 0 0 1 1 1 1 1 1 ?dose <- scan() ?1 2 4 8 16 32 1 2 4 8 16 32
Fit two models by doing the following.
ldose <- log(dose)/log(2) #convert to base-2 log dose ?
ldose #have a look ?
| y <- cbind(num.killed, 20-num.killed) ? ? ? ? ? ? ? ? ? ? ?| #add number survived |
| ---------------------------------------------------------- | -------------------- |
| fit1 <- glm(y ~ ldose * sex, family=binomial(link=probit)) | ? ? ? ? ? ? ? ? ? ? ?|
| fit2 <- glm(y ~ sex + ldose, family=binomial(link=probit))
You may also run the following lines and refer to the chi-square distribution table.anova(fit1,test="Chisq") |
| ------------------------ |
| summary(fit2)
No other R commands are allowed.?Hand in your answers to the following for assessment. 1. What model is fitted in fit1? Write it formally and define all the terms.[4]2. How is the model in fit2 differ from that in fit1?[2]3. Does the model in fit1 fit the data adequately? Use deviance to answer this question.[2]
Can the model in fit1 be simplified to the model in fit2? Use change in deviance to answer
this question. [2]Can sex be removed from the model in fit2? Use change in deviance to answer this question. [2]
What are the maximum likelihood estimates of the parameters of the additive model? What
are their standard errors? Test the significance of each parameter using its estimate and
standard error. [4]How does the probability of a kill change with log dose and sex of the budworm moth according to the additive model? [4
(a) Derive the survival function S(t) of a lifetime T ? E xp(?). Find ?logS(t) and comment on it.
(b) Calculate the Kaplan-Meier estimate for each group in the following.
Treatment Group:
6,6,6,6*,7,9*,10,10*,11*,13,16,17*,19*,20*,22,23,25*,32*,32*,34*,35
Control Group (no treatment):
1,1,2,2,3,4,5,5,8,8,8,8,11,11,12,15,17,22,23
Note that * indicates right censored data.
(c) Use the log rank test to compare the two groups of lifetimes.
All the answers should be obtained by hand. Calculators may be used. Some intermediate steps
should be included. You may check your answers using R, but do not hand in any R output
1
Fit1模型使用的是logistic回歸模型。
yi = π + ε~ B (1, πi ) independent,
log(π)= β0?sex+ β1ldose+β2sexldose
2
模型1中將sex 和ldose的乘積作為一個自變量,考慮到sex,lodose以及他們的交叉影響,而模型2將sex 和ldose分別作為兩個自變量來對y進行回歸預測模型。
3

從方差分析結果來看,可以看到ldose sex 以及l(fā)dose和sex的乘積三個變量的偏差值值的p值都遠遠小于0.05,也就是這三個變量對budworm moths killed這個變量都有顯著的影響。但是他們的deviance resid 偏差殘差值較大,即模型的預測值與實驗結果有較大偏差,因此可以認為模型擬合度較差。
4

從偏差殘差值來看擬合模型1可以簡化成模型2,因為他們的deviance residuals相差很大,模型2的偏差殘差值要明顯低于模型1.,說明模型2的擬合效果要好于模型1,從而可以刪去性別*ldose這個變量。
5

從模型2的結果來看,性別這個變量的相關系數(shù)的p值遠小于0.001,即性別對死亡率由明顯的影響,因此不能從模型中去除。
6
模型的極大似然估計參數(shù)為-0.93285 -0.95和0.42948.他們的標準差為0.19043,0.19120和0.05992。
從顯著性p值和預測的系數(shù)和標準差的關系來看,p值越小,如ldoese這個變量,那么他的標準差越小,而估計的參數(shù)就越大,對死亡率的影響也越大。
7
因此,根據(jù)變量的p值來看,當sex和ldose改變的時候,有99%以上的把握可以拒絕原假設即性別與ldose對死亡率沒有影響,即引起死亡率的變化。