# 9. harjoitukset ################# # 9.3 # influenza <- read.table("C:\\Kurssit\\Glim\\Glim02\\Datat\\influenza.txt", header = TRUE, sep = ",") names(influenza) [1] "treatment" "response" "frequency" # (a) flu.r <-glm(frequency ~ treatment + response,data=influenza, family=poisson) flu.f <- glm(frequency ~ treatment*response,data=influenza, family=poisson) anova(flu.r,flu.f,test="Chisq") flu.r$deviance; flu.f$deviance; flu.r$df.residual; flu.f$df.residual ts.r<- matrix(data = predict(flu.r,type = "response"), nrow = 2, ncol = 3, byrow = T) ts.f<- matrix(data = predict(flu.f,type = "response"), nrow = 2, ncol = 3, byrow = T) # Testi pearson.res<- matrix(data = residuals(flu.r,type = "pearson"), nrow = 2, ncol = 3, byrow = T) sum(pearson.res^2) # Pearsonin Khin-neliötesti # Khi^2-testisuure 17.64518, vapausasteet=2 pchisq(17.64518, 2, lower.tail = F) # [1] 0.0001473662 # Riippumattomuushypoteesi hylätään # (b) dev.res<- matrix(data = residuals(flu.r,type = "deviance"), nrow = 2, ncol = 3, byrow = T) pearson.res<- matrix(data = residuals(flu.r,type = "pearson"), nrow = 2, ncol = 3, byrow = T) > dev.res [,1] [,2] [,3] [1,] 2.040115 -1.629720 -1.246900 [2,] -2.615460 1.468817 1.127679 > pearson.res [,1] [,2] [,3] [1,] 2.206144 -1.504355 -1.153459 [2,] -2.298592 1.567394 1.201794 # Havainnot y_11 ja y_21 vaikuttavat eniten. 25 on "liian suuri" ja 6 "liian pieni", # jotta H_0 olisi uskottava.