ST5213 Appendix: R output
Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit
ST5213
Appendix: R output
Chi-square statistics
> round(qchisq(0.05, df=1:130, lower.tail = FALSE), 3)
[1] |
3.841 |
5.991 |
7.815 |
9.488 |
11.070 |
12.592 |
14.067 |
15.507 |
16.919 |
18.307 |
[11] |
19.675 |
21.026 |
22.362 |
23.685 |
24.996 |
26.296 |
27.587 |
28.869 |
30.144 |
31.410 |
[21] |
32.671 |
33.924 |
35.172 |
36.415 |
37.652 |
38.885 |
40.113 |
41.337 |
42.557 |
43.773 |
[31] |
44.985 |
46.194 |
47.400 |
48.602 |
49.802 |
50.998 |
52.192 |
53.384 |
54.572 |
55.758 |
[41] |
56.942 |
58.124 |
59.304 |
60.481 |
61.656 |
62.830 |
64.001 |
65.171 |
66.339 |
67.505 |
[51] |
68.669 |
69.832 |
70.993 |
72.153 |
73.311 |
74.468 |
75.624 |
76.778 |
77.931 |
79.082 |
[61] |
80.232 |
81.381 |
82.529 |
83.675 |
84.821 |
85.965 |
87.108 |
88.250 |
89.391 |
90.531 |
[71] |
91.670 |
92.808 |
93.945 |
95.081 |
96.217 |
97.351 |
98.484 |
99.617 |
100.749 |
101.879 |
[81] |
103.010 |
104.139 |
105.267 |
106.395 |
107.522 |
108.648 |
109.773 |
110.898 |
112.022 |
113.145 |
[91] |
114.268 |
115.390 |
116.511 |
117.632 |
118.752 |
119.871 |
120.990 |
122.108 |
123.225 |
124.342 |
[101] |
125.458 |
126.574 |
127.689 |
128.804 |
129.918 |
131.031 |
132.144 |
133.257 |
134.369 |
135.480 |
[111] |
136.591 |
137.701 |
138.811 |
139.921 |
141.030 |
142.138 |
143.246 |
144.354 |
145.461 |
146.567 |
[121] |
147.674 |
148.779 |
149.885 |
150.989 |
152.094 |
153.198 |
154.302 |
155.405 |
156.508 |
157.610 |
Question 1
> library(Sleuth3)
> dat <- ex2012
> str(dat)
’data.frame’: 120 obs. of 3 variables:
$ Group: Factor w/ 2 levels "Case","Control": 2 2 2 2 2 2 2 2 2 2 ...
$ CK : int 52 20 28 30 40 24 15 22 42 130 ...
$ H : num 83.5 77 86.5 104 83 78.8 87 91 65.5 80.3 ...
> levels(dat$Group)
[1] "Case" "Control"
> dat$Group <- relevel(dat$Group, ref="Control")
> str(dat)
’data.frame’: 120 obs. of 3 variables:
$ Group: Factor w/ 2 levels "Control","Case": 1 1 1 1 1 1 1 1 1 1 ...
$ CK : int 52 20 28 30 40 24 15 22 42 130 ...
$ H : num 83.5 77 86.5 104 83 78.8 87 91 65.5 80.3 ...
> range(dat$CK) [1] 15 925
> range(dat$H) [1] 34 118
> plot(CK ~ H, dat, pch=as.character(as.numeric(Group)))
40 60 80 100 120
H
> plot(log(CK) ~ H, dat, pch=as.character(as.numeric(Group)))
40 60 80 100 120
H
> (fm <- glm(Group ~ CK + H, family = binomial, data=dat))
Call: glm(formula = Group ~ CK + H, family = binomial, data = dat)
Coefficients: |
|
|
(Intercept) |
CK |
H |
-16.16695 |
0.06838 |
0.12732 |
Degrees of Freedom: 119 Total (i.e. Null); 117 Residual Null Deviance: 149.8
Residual Deviance: 62.22 AIC: 68.22
> (fm1 <- update(fm, .~. + I(H^2)))
Call: glm(formula = Group ~ CK + H + I(H^2), family = binomial, data = dat) Coefficients:
(Intercept) CK H I(H^2)
-32.806114 0.069289 0.494264 -0.002002
Degrees of Freedom: 119 Total (i.e. Null); 116 Residual Null Deviance: 149.8
Residual Deviance: 61.68 AIC: 69.68
> anova(fm, fm1, test = "Chisq") Analysis of Deviance Table
Model 1: Group ~ CK + H
Model 2: Group ~ CK + H + I(H^2)
Resid. Df Resid. Dev Df Deviance Pr(>Chi)
1 |
117 |
62.224 |
|
2 |
116 |
61.675 1 |
0.54905 0.4587 |
> (fm1 <- update(fm, .~. + I(CK^2)))
Call: glm(formula = Group ~ CK + H + I(CK^2), family = binomial, data = dat) Coefficients:
(Intercept) CK H I(CK^2)
-1.664e+01 7.859e-02 1.292e-01 -7.130e-05
Degrees of Freedom: 119 Total (i.e. Null); 116 Residual Null Deviance: 149.8
Residual Deviance: 61.79 AIC: 69.79
> anova(fm, fm1, test = "Chisq") Analysis of Deviance Table
Model 1: Group ~ CK + H
Model 2: Group ~ CK + H + I(CK^2)
Resid. Df Resid. Dev Df Deviance Pr(>Chi)
1 |
117 |
62.224 |
|
2 |
116 |
61.789 1 |
0.43496 0.5096 |
> (fm1 <- update(fm, .~. + I(H*CK)))
Call: glm(formula = Group ~ CK + H + I(H * CK), family = binomial, data = dat)
Coefficients: |
|
||
(Intercept) |
CK |
H |
I(H * CK) |
-10.05172 |
-0.05812 |
0.05818 |
0.00147 |
Degrees of Freedom: 119 Total (i.e. Null); 116 Residual Null Deviance: 149.8
Residual Deviance: 61.13 AIC: 69.13
> anova(fm, fm1, test = "Chisq")
Analysis of Deviance Table
Model 1: Group ~ CK + H
Model 2: Group ~ CK + H + I(H * CK)
Resid. Df Resid. Dev Df Deviance Pr(>Chi)
1 |
117 |
62.224 |
|
|
2 |
116 |
61.128 1 |
1.0961 |
0.2951 |
> drop1(fm, test = "Chisq")
Single term deletions Model:
Group ~ CK + H
Df Deviance AIC LRT Pr(>Chi)
CK 1 128.168 132.168 65.944 4.64e-16
H 1 85.647 89.647 23.423 1.30e-06
> (fm <- glm(Group ~ log(CK) + H, family = binomial, data=dat))
Call: glm(formula = Group ~ log(CK) + H, family = binomial, data = dat)
Coefficients: |
|
|
(Intercept) |
log(CK) |
H |
-28.9134 |
4.0204 |
0.1365 |
Degrees of Freedom: 119 Total (i.e. Null); 117 Residual Null Deviance: 149.8
Residual Deviance: 61.99 AIC: 67.99
> (fm1 <- update(fm, .~. + I(H^2)))
Call: glm(formula = Group ~ log(CK) + H + I(H^2), family = binomial, data = dat)
Coefficients: |
|
||
(Intercept) |
log(CK) |
H |
I(H^2) |
-39.511498 |
3.987467 |
0.376885 |
-0.001328 |
Degrees of Freedom: 119 Total (i.e. Null); 116 Residual Null Deviance: 149.8
Residual Deviance: 61.75 AIC: 69.75
> anova(fm, fm1, test = "Chisq") Analysis of Deviance Table
Model 1: Group ~ log(CK) + H
Model 2: Group ~ log(CK) + H + I(H^2) Resid. Df Resid. Dev
2022-11-23