dkm@sierpinski:~/sigmafield/5300$ R

R version 3.3.2 (2016-10-31) -- "Sincere Pumpkin Patch"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> mydata=read.csv('table-4-3.csv')
> mydata
    color spine width satell weight y
1       3     3  28.3      8   3050 1
2       4     3  22.5      0   1550 0
3       2     1  26.0      9   2300 1
4       4     3  24.8      0   2100 0
5       4     3  26.0      4   2600 1
6       3     3  23.8      0   2100 0
7       2     1  26.5      0   2350 0
8       4     2  24.7      0   1900 0
9       3     1  23.7      0   1950 0
10      4     3  25.6      0   2150 0
11      4     3  24.3      0   2150 0
12      3     3  25.8      0   2650 0
13      3     3  28.2     11   3050 1
14      5     2  21.0      0   1850 0
15      3     1  26.0     14   2300 1
16      2     1  27.1      8   2950 1
17      3     3  25.2      1   2000 1
18      3     3  29.0      1   3000 1
19      5     3  24.7      0   2200 0
20      3     3  27.4      5   2700 1
21      3     2  23.2      4   1950 1
22      2     2  25.0      3   2300 1
23      3     1  22.5      1   1600 1
24      4     3  26.7      2   2600 1
25      5     3  25.8      3   2000 1
26      5     3  26.2      0   1300 0
27      3     3  28.7      3   3150 1
28      3     1  26.8      5   2700 1
29      5     3  27.5      0   2600 0
30      3     3  24.9      0   2100 0
31      2     1  29.3      4   3200 1
32      2     3  25.8      0   2600 0
33      3     2  25.7      0   2000 0
34      3     1  25.7      8   2000 1
35      3     1  26.7      5   2700 1
36      5     3  23.7      0   1850 0
37      3     3  26.8      0   2650 0
38      3     3  27.5      6   3150 1
39      5     3  23.4      0   1900 0
40      3     3  27.9      6   2800 1
41      4     3  27.5      3   3100 1
42      2     1  26.1      5   2800 1
43      2     1  27.7      6   2500 1
44      3     1  30.0      5   3300 1
45      4     1  28.5      9   3250 1
46      4     3  28.9      4   2800 1
47      3     3  28.2      6   2600 1
48      3     3  25.0      4   2100 1
49      3     3  28.5      3   3000 1
50      3     1  30.3      3   3600 1
51      5     3  24.7      5   2100 1
52      3     3  27.7      5   2900 1
53      2     1  27.4      6   2700 1
54      3     3  22.9      4   1600 1
55      3     1  25.7      5   2000 1
56      3     3  28.3     15   3000 1
57      3     3  27.2      3   2700 1
58      4     3  26.2      3   2300 1
59      3     1  27.8      0   2750 0
60      5     3  25.5      0   2250 0
61      4     3  27.1      0   2550 0
62      4     3  24.5      5   2050 1
63      4     1  27.0      3   2450 1
64      3     3  26.0      5   2150 1
65      3     3  28.0      1   2800 1
66      3     3  30.0      8   3050 1
67      3     3  29.0     10   3200 1
68      3     3  26.2      0   2400 0
69      3     1  26.5      0   1300 0
70      3     3  26.2      3   2400 1
71      4     3  25.6      7   2800 1
72      4     3  23.0      1   1650 1
73      4     3  23.0      0   1800 0
74      3     3  25.4      6   2250 1
75      4     3  24.2      0   1900 0
76      3     2  22.9      0   1600 0
77      4     2  26.0      3   2200 1
78      3     3  25.4      4   2250 1
79      4     3  25.7      0   1200 0
80      3     3  25.1      5   2100 1
81      4     2  24.5      0   2250 0
82      5     3  27.5      0   2900 0
83      4     3  23.1      0   1650 0
84      4     1  25.9      4   2550 1
85      3     3  25.8      0   2300 0
86      5     3  27.0      3   2250 1
87      3     3  28.5      0   3050 0
88      5     1  25.5      0   2750 0
89      5     3  23.5      0   1900 0
90      3     2  24.0      0   1700 0
91      3     1  29.7      5   3850 1
92      3     1  26.8      0   2550 0
93      5     3  26.7      0   2450 0
94      3     1  28.7      0   3200 0
95      4     3  23.1      0   1550 0
96      3     1  29.0      1   2800 1
97      4     3  25.5      0   2250 0
98      4     3  26.5      1   1967 1
99      4     3  24.5      1   2200 1
100     4     3  28.5      1   3000 1
101     3     3  28.2      1   2867 1
102     3     3  24.5      1   1600 1
103     3     3  27.5      1   2550 1
104     3     2  24.7      4   2550 1
105     3     1  25.2      1   2000 1
106     4     3  27.3      1   2900 1
107     3     3  26.3      1   2400 1
108     3     3  29.0      1   3100 1
109     3     3  25.3      2   1900 1
110     3     3  26.5      4   2300 1
111     3     3  27.8      3   3250 1
112     3     3  27.0      6   2500 1
113     4     3  25.7      0   2100 0
114     3     3  25.0      2   2100 1
115     3     3  31.9      2   3325 1
116     5     3  23.7      0   1800 0
117     5     3  29.3     12   3225 1
118     4     3  22.0      0   1400 0
119     3     3  25.0      5   2400 1
120     4     3  27.0      6   2500 1
121     4     3  23.8      6   1800 1
122     2     1  30.2      2   3275 1
123     4     3  26.2      0   2225 0
124     3     3  24.2      2   1650 1
125     3     3  27.4      3   2900 1
126     3     2  25.4      0   2300 0
127     4     3  28.4      3   3200 1
128     5     3  22.5      4   1475 1
129     3     3  26.2      2   2025 1
130     3     1  24.9      6   2300 1
131     2     2  24.5      6   1950 1
132     3     3  25.1      0   1800 0
133     3     1  28.0      4   2900 1
134     5     3  25.8     10   2250 1
135     3     3  27.9      7   3050 1
136     3     3  24.9      0   2200 0
137     3     1  28.4      5   3100 1
138     4     3  27.2      5   2400 1
139     3     2  25.0      6   2250 1
140     3     3  27.5      6   2625 1
141     3     1  33.5      7   5200 1
142     3     3  30.5      3   3325 1
143     4     3  29.0      3   2925 1
144     3     1  24.3      0   2000 0
145     3     3  25.8      0   2400 0
146     5     3  25.0      8   2100 1
147     3     1  31.7      4   3725 1
148     3     3  29.5      4   3025 1
149     4     3  24.0     10   1900 1
150     3     3  30.0      9   3000 1
151     3     3  27.6      4   2850 1
152     3     3  26.2      0   2300 0
153     3     1  23.1      0   2000 0
154     3     1  22.9      0   1600 0
155     5     3  24.5      0   1900 0
156     3     3  24.7      4   1950 1
157     3     3  28.3      0   3200 0
158     3     3  23.9      2   1850 1
159     4     3  23.8      0   1800 0
160     4     2  29.8      4   3500 1
161     3     3  26.5      4   2350 1
162     3     3  26.0      3   2275 1
163     3     3  28.2      8   3050 1
164     5     3  25.7      0   2150 0
165     3     3  26.5      7   2750 1
166     3     3  25.8      0   2200 0
167     4     3  24.1      0   1800 0
168     4     3  26.2      2   2175 1
169     4     3  26.1      3   2750 1
170     4     3  29.0      4   3275 1
171     2     1  28.0      0   2625 0
172     5     3  27.0      0   2625 0
173     3     2  24.5      0   2000 0
> attach(mydata)
> fit0=glm(y~1,binomial)
> summary(fit0)

Call:
glm(formula = y ~ 1, family = binomial)

Deviance Residuals: 
    Min       1Q   Median       3Q      Max  
-1.4326  -1.4326   0.9421   0.9421   0.9421  

Coefficients:
            Estimate Std. Error z value Pr(>|z|)    
(Intercept)   0.5824     0.1585   3.673 0.000239 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

(Dispersion parameter for binomial family taken to be 1)

    Null deviance: 225.76  on 172  degrees of freedom
Residual deviance: 225.76  on 172  degrees of freedom
AIC: 227.76

Number of Fisher Scoring iterations: 4

> odds=exp(.5824)
> odds
[1] 1.79033
> odds/(1+odds)
[1] 0.6416195
> fit1=glm(y~width,binomial)
> summary(fit1)

Call:
glm(formula = y ~ width, family = binomial)

Deviance Residuals: 
    Min       1Q   Median       3Q      Max  
-2.0281  -1.0458   0.5480   0.9066   1.6942  

Coefficients:
            Estimate Std. Error z value Pr(>|z|)    
(Intercept) -12.3508     2.6287  -4.698 2.62e-06 ***
width         0.4972     0.1017   4.887 1.02e-06 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

(Dispersion parameter for binomial family taken to be 1)

    Null deviance: 225.76  on 172  degrees of freedom
Residual deviance: 194.45  on 171  degrees of freedom
AIC: 198.45

Number of Fisher Scoring iterations: 4

> fit2=glm(y~width+weight,binomial)
> summary(fit2)

Call:
glm(formula = y ~ width + weight, family = binomial)

Deviance Residuals: 
    Min       1Q   Median       3Q      Max  
-2.1127  -1.0344   0.5304   0.9006   1.7207  

Coefficients:
              Estimate Std. Error z value Pr(>|z|)   
(Intercept) -9.3547261  3.5280465  -2.652  0.00801 **
width        0.3067892  0.1819473   1.686  0.09177 . 
weight       0.0008338  0.0006716   1.241  0.21445   
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

(Dispersion parameter for binomial family taken to be 1)

    Null deviance: 225.76  on 172  degrees of freedom
Residual deviance: 192.89  on 170  degrees of freedom
AIC: 198.89

Number of Fisher Scoring iterations: 4

> plot(weight,width)
> anova(fit1,fit0,test="LRT")
Analysis of Deviance Table

Model 1: y ~ width
Model 2: y ~ 1
  Resid. Df Resid. Dev Df Deviance  Pr(>Chi)    
1       171     194.45                          
2       172     225.76 -1  -31.306 2.204e-08 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> anova(fit0,fit1,test="LRT")
Analysis of Deviance Table

Model 1: y ~ 1
Model 2: y ~ width
  Resid. Df Resid. Dev Df Deviance  Pr(>Chi)    
1       172     225.76                          
2       171     194.45  1   31.306 2.204e-08 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> anova(fit1,fit2,test="LRT")
Analysis of Deviance Table

Model 1: y ~ width
Model 2: y ~ width + weight
  Resid. Df Resid. Dev Df Deviance Pr(>Chi)
1       171     194.45                     
2       170     192.89  1   1.5608   0.2116
> y1=fitted(fit1)
> y2=fitted(fit2)
> plot(width,y)
> plot(width,y1)
> plot(width,y2)
> plot(width,y1-y2)
> plot(weight,y1-y2)
> plot(weight,width)
> color
  [1] 3 4 2 4 4 3 2 4 3 4 4 3 3 5 3 2 3 3 5 3 3 2 3 4 5 5 3 3 5 3 2 2 3 3 3 5 3
 [38] 3 5 3 4 2 2 3 4 4 3 3 3 3 5 3 2 3 3 3 3 4 3 5 4 4 4 3 3 3 3 3 3 3 4 4 4 3
 [75] 4 3 4 3 4 3 4 5 4 4 3 5 3 5 5 3 3 3 5 3 4 3 4 4 4 4 3 3 3 3 3 4 3 3 3 3 3
[112] 3 4 3 3 5 5 4 3 4 4 2 4 3 3 3 4 5 3 3 2 3 3 5 3 3 3 4 3 3 3 3 4 3 3 5 3 3
[149] 4 3 3 3 3 3 5 3 3 3 4 4 3 3 3 5 3 3 4 4 4 4 2 5 3
> fit3=glm(y~width+color,binomial)
> summary(fit3)

Call:
glm(formula = y ~ width + color, family = binomial)

Deviance Residuals: 
    Min       1Q   Median       3Q      Max  
-2.1692  -0.9889   0.5429   0.8700   1.9742  

Coefficients:
            Estimate Std. Error z value Pr(>|z|)    
(Intercept)  -9.5618     2.8828  -3.317  0.00091 ***
width         0.4583     0.1040   4.406 1.05e-05 ***
color        -0.5090     0.2237  -2.276  0.02286 *  
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

(Dispersion parameter for binomial family taken to be 1)

    Null deviance: 225.76  on 172  degrees of freedom
Residual deviance: 189.12  on 170  degrees of freedom
AIC: 195.12

Number of Fisher Scoring iterations: 4

> anova(fit3,fit1)
Analysis of Deviance Table

Model 1: y ~ width + color
Model 2: y ~ width
  Resid. Df Resid. Dev Df Deviance
1       170     189.12            
2       171     194.45 -1  -5.3315
> anova(fit1,fit3)
Analysis of Deviance Table

Model 1: y ~ width
Model 2: y ~ width + color
  Resid. Df Resid. Dev Df Deviance
1       171     194.45            
2       170     189.12  1   5.3315
> anova(fit1,fit3,test="LRT")
Analysis of Deviance Table

Model 1: y ~ width
Model 2: y ~ width + color
  Resid. Df Resid. Dev Df Deviance Pr(>Chi)  
1       171     194.45                       
2       170     189.12  1   5.3315  0.02094 *
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> plot(width,color)
> summary(fit3)

Call:
glm(formula = y ~ width + color, family = binomial)

Deviance Residuals: 
    Min       1Q   Median       3Q      Max  
-2.1692  -0.9889   0.5429   0.8700   1.9742  

Coefficients:
            Estimate Std. Error z value Pr(>|z|)    
(Intercept)  -9.5618     2.8828  -3.317  0.00091 ***
width         0.4583     0.1040   4.406 1.05e-05 ***
color        -0.5090     0.2237  -2.276  0.02286 *  
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

(Dispersion parameter for binomial family taken to be 1)

    Null deviance: 225.76  on 172  degrees of freedom
Residual deviance: 189.12  on 170  degrees of freedom
AIC: 195.12

Number of Fisher Scoring iterations: 4

> y3=fitted(fit3)
> plot(color,y3-y2)
> plot(color,y3-y1)
> plot(width,y3-y1)
> plot(width,y3)
> fit4=glm(y~width+color+spine,binomial)
> summary(fit4)

Call:
glm(formula = y ~ width + color + spine, family = binomial)

Deviance Residuals: 
    Min       1Q   Median       3Q      Max  
-2.1214  -0.9566   0.5332   0.8901   1.9791  

Coefficients:
            Estimate Std. Error z value Pr(>|z|)    
(Intercept)  -9.8491     2.9065  -3.389 0.000702 ***
width         0.4572     0.1039   4.400 1.08e-05 ***
color        -0.6010     0.2413  -2.491 0.012747 *  
spine         0.2534     0.2405   1.054 0.291966    
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

(Dispersion parameter for binomial family taken to be 1)

    Null deviance: 225.76  on 172  degrees of freedom
Residual deviance: 188.02  on 169  degrees of freedom
AIC: 196.02

Number of Fisher Scoring iterations: 4

> summary(fit3)

Call:
glm(formula = y ~ width + color, family = binomial)

Deviance Residuals: 
    Min       1Q   Median       3Q      Max  
-2.1692  -0.9889   0.5429   0.8700   1.9742  

Coefficients:
            Estimate Std. Error z value Pr(>|z|)    
(Intercept)  -9.5618     2.8828  -3.317  0.00091 ***
width         0.4583     0.1040   4.406 1.05e-05 ***
color        -0.5090     0.2237  -2.276  0.02286 *  
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

(Dispersion parameter for binomial family taken to be 1)

    Null deviance: 225.76  on 172  degrees of freedom
Residual deviance: 189.12  on 170  degrees of freedom
AIC: 195.12

Number of Fisher Scoring iterations: 4

> anova(fit3,fit4,test="LRT")
Analysis of Deviance Table

Model 1: y ~ width + color
Model 2: y ~ width + color + spine
  Resid. Df Resid. Dev Df Deviance Pr(>Chi)
1       170     189.12                     
2       169     188.02  1   1.1053   0.2931
> plot(color,spine)
> plot(width,spine)
> y4=fitted(fit4)
> plot(color,y3-y4)
> plot(spine,y3-y4)
> plot(width,y3-y4)
> plot(spine,y3-y4)
> cor(weight,width)
[1] 0.8868715
> ?cor
> cor(color,spine)
[1] 0.3785016
> cor(weight,color)
[1] -0.2507772
> cor(weight,spine)
[1] -0.1664817
> cor(width,spine)
[1] -0.1218946
> cor(width,color)
[1] -0.2643863
> qnorm(.05)
[1] -1.644854
> zb=qnorm(1-.05)
> za=qnorm(1-.05/2)
> pi1=.7
> pi2=.8
> pow=(za+zb)^2*(pi1*(1-pi1)+pi2*(1-pi2))/(pi1-pi2)^2
> pow
[1] 480.8043
> pi1=.3
> pow=(za+zb)^2*(pi1*(1-pi1)+pi2*(1-pi2))/(pi1-pi2)^2
> pow
[1] 19.23217
> 
