tab <- read.csv2 (file = "aids.csv") summary (tab) # Poissonovska regrese time <- 1:36 # vykresleni dat plot(time,tab$number,type="p",pch=20,ylab="number of AIDS", xlab="time",main="Poisson regression") # definice modelu glm1 <- lm(number ~ time, data = tab) summary(glm1) glm2 <- glm(number ~ time, family=poisson("log"), data = tab) summary(glm2) glm3 <- glm(number ~ time, family=poisson("sqrt"), data = tab) summary(glm3) # vykresleni regresnich krivek #points(time,fitted(glm1),col=2) xx<-seq(0,37,by=0.01) yA.logit<-predict(glm1,list(time=xx),type="response") lines(xx,yA.logit,col=2,lwd=2) yB.logit<-predict(glm2,list(time=xx),type="response") lines(xx,yB.logit,col=3,lwd=2) yC.logit<-predict(glm3,list(time=xx),type="response") lines(xx,yC.logit,col=4,lwd=2) legend("topleft",col=c(2,3,4),lty=c(1,1,1),lwd=c(2,2,2),legend=c("linear","log-linear","square-root")) # overeni normality residui plot(glm1,which=2) shapiro.test(residuals(glm1)) plot(glm2,which=2) shapiro.test(residuals(glm2)) plot(glm3,which=2) shapiro.test(residuals(glm3))