One of the built in datasets in R is called InsectSprays and is accessed by writing InsectSprays.The data set consists of 72 observations of two variables from different agricultural fields. The variables are:

Fit a generalized linear model with canonical link to the data. Use count as the response and the factor spray as a covariate. Do not include an intercept term in the model. You may also need to perform additional commands (in addition to fitting the model) on your fitted GLM-object.

Based on your data analysis answer the following questions:

  1. Which type of GLM did you fit? Poisson.

  2. Which link function did you use? Log.

  3. What is the estimated regression coefficient for effect of spray of category A? 2.67

  4. What is the estimated variance of the regression coefficient for the effect of spray of category C? 0.04

  5. Perform a deviance test and report the p-value. 0.006

  6. Is the conclusion from the deviance test that our model is good? False

  7. Give the estimated covariance between the estimated effect of spray B and spray F. 0.00

  8. Perform an test with \(H_0\) stating that the regression coefficient of for spray B is equal to the regression coefficient for spray F, vs. the two-sided alternative. Report the p-value from this test. 0.41

fit2=glm(count~spray-1,family="poisson",data=InsectSprays)
summary(fit2)
## 
## Call:
## glm(formula = count ~ spray - 1, family = "poisson", data = InsectSprays)
## 
## Deviance Residuals: 
##     Min       1Q   Median       3Q      Max  
## -2.3852  -0.8876  -0.1482   0.6063   2.6922  
## 
## Coefficients:
##        Estimate Std. Error z value Pr(>|z|)    
## sprayA  2.67415    0.07581  35.274  < 2e-16 ***
## sprayB  2.73003    0.07372  37.032  < 2e-16 ***
## sprayC  0.73397    0.20000   3.670 0.000243 ***
## sprayD  1.59263    0.13019  12.233  < 2e-16 ***
## sprayE  1.25276    0.15430   8.119 4.71e-16 ***
## sprayF  2.81341    0.07071  39.788  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for poisson family taken to be 1)
## 
##     Null deviance: 2264.808  on 72  degrees of freedom
## Residual deviance:   98.329  on 66  degrees of freedom
## AIC: 376.59
## 
## Number of Fisher Scoring iterations: 5
1-pchisq(fit2$deviance,fit2$df.residual)
## [1] 0.006054201
vcov(fit2)
##             sprayA      sprayB     sprayC     sprayD     sprayE sprayF
## sprayA 0.005747126 0.000000000 0.00000000 0.00000000 0.00000000  0.000
## sprayB 0.000000000 0.005434783 0.00000000 0.00000000 0.00000000  0.000
## sprayC 0.000000000 0.000000000 0.03999995 0.00000000 0.00000000  0.000
## sprayD 0.000000000 0.000000000 0.00000000 0.01694915 0.00000000  0.000
## sprayE 0.000000000 0.000000000 0.00000000 0.00000000 0.02380952  0.000
## sprayF 0.000000000 0.000000000 0.00000000 0.00000000 0.00000000  0.005
C=matrix(c(0,1,0,0,0,-1),ncol=6)
Cbeta=C%*%fit2$coefficients
covCbeta=C%*%vcov(fit2)%*%t(C)
covCbeta
##            [,1]
## [1,] 0.01043478
testobs=t(Cbeta)%*%solve(covCbeta)%*%(Cbeta)
testobs
##           [,1]
## [1,] 0.6662806
1-pchisq(testobs,1)
##           [,1]
## [1,] 0.4143514
# alternatively since orth sprays
testobs2=(fit2$coefficients[2]-fit2$coefficients[6])/sqrt(summary(fit2)$coefficients[2,2]^2+summary(fit2)$coefficients[6,2]^2)
testobs2^2
##    sprayB 
## 0.6662806
1-pchisq(testobs2^2,1)
##    sprayB 
## 0.4143514
# could also use LRT, but a bit mess to recode