tab <- read.csv2 (file = "beetle.csv") summary (tab) tab$proportions <- tab$killed / tab$population # Logisticka regrese # Vykresleni dat plot(tab$dose, tab$proportions,pch=20,xlab="CS2",ylab="umrtnost") # definice GLM modelu glmmod1 <- glm(formula = cbind(killed, population - killed) ~ dose, family = binomial(logit),data = tab) summary(glmmod1) # vykresleni regresni krivky t <- seq(from = min(tab$dose), to=max(tab$dose), by=0.001) lines(t,predict(glmmod1,data.frame(dose=t),type="response"),col="red") # overeni normality residui plot(glmmod1,which=2) shapiro.test(residuals(glmmod1)) # Probitovy model # Vykresleni dat plot(tab$dose,tab$proportions,pch=20,xlab="CS2",ylab="umrtnost") # definice GLM modelu glmmod2 <- glm(formula = cbind(killed, population - killed) ~ dose, family = binomial(probit),data = tab) summary(glmmod2) # vykresleni regresni krivky t <- seq(from=min(tab$dose),to=max(tab$dose),by=0.001) lines(t,predict(glmmod2,data.frame(dose=t),type="response"),col="red") # overeni normality residui plot(glmmod2,which=2) shapiro.test(residuals(glmmod2)) # komplementarni log-log # Vykresleni dat plot(tab$dose,tab$proportions,pch=20,xlab="CS2",ylab="umrtnost") # definice GLM modelu glmmod3 <- glm(formula = cbind(killed, population - killed) ~ dose, family = binomial(link="cloglog"),data = tab) summary(glmmod3) # vykresleni regresni krivky t <- seq(from=min(tab$dose),to=max(tab$dose), by=0.001) lines(t,predict(glmmod3,data.frame(dose=t),type="response"),col="red") # overeni normality residui plot(glmmod3,which=2) shapiro.test(residuals(glmmod3)) # vsechny tri modely plot(tab$dose, tab$proportions,pch=20,xlab="CS2",ylab="umrtnost") lines(t,predict(glmmod1,data.frame(dose=t),type="response"),col="red") lines(t,predict(glmmod2,data.frame(dose=t),type="response"),col="green") lines(t,predict(glmmod3,data.frame(dose=t),type="response"),col="blue")