前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >专栏 >R语言代做编程辅导和解答GLM Coursework

R语言代做编程辅导和解答GLM Coursework

原创
作者头像
拓端
发布2022-12-13 16:46:20
发布2022-12-13 16:46:20
42500
代码可运行
举报
文章被收录于专栏:拓端tecdat拓端tecdat
运行总次数:0
代码可运行

全文链接: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

代码语言:javascript
代码运行次数:0
运行
复制
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.

代码语言:javascript
代码运行次数:0
运行
复制
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.

代码语言:javascript
代码运行次数:0
运行
复制
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.

代码语言:javascript
代码运行次数:0
运行
复制
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]

  1. Can the model in fit1 be simplified to the model in fit2? Use change in deviance to answer this question. [2]
  2. Can sex be removed from the model in fit2? Use change in deviance to answer this question. [2]
  3. 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]
  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 以及ldose和sex的乘积三个变量的偏差值值的p值都远远小于0.05,也就是这三个变量对budworm moths killed这个变量都有显著的影响。但是他们的deviance resid 偏差残差值较大,即模型的预测值与实验结果有较大偏差,因此可以认为模型拟合度较差。

4

从偏差残差值来看拟合模型1可以简化成模型2,因为他们的deviance residuals相差很大,模型2的偏差残差值要明显低于模型1.,说明模型2的拟合效果要好于模型1,从而可以删去性别*ldose这个变量。

5

从模型2的结果来看,性别这个变量的相关系数的p值远小于0.001,即性别对死亡率由明显的影响,因此不能从模型中去除。

6

模型的极大似然估计参数为-0.93285 -0.95和0.42948.他们的标准差为0.19043,0.19120和0.05992。

从显著性p值和预测的系数和标准差的关系来看,p值越小,如ldoese这个变量,那么他的标准差越小,而估计的参数就越大,对死亡率的影响也越大。

7

因此,根据变量的p值来看,当sex和ldose改变的时候,有99%以上的把握可以拒绝原假设即性别与ldose对死亡率没有影响,即引起死亡率的变化。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 全文链接:http://tecdat.cn/?p=30821
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档