############# ## Cviceni 1 ############# fullmoon <- read.table("fullmoon.txt", header=TRUE) dim(fullmoon) fullmoon summary(fullmoon) Moon <- factor(fullmoon$Moon, levels=c("Before", "During", "After")) table(Moon, fullmoon$Moon) fullmoon$Moon <- Moon Month <- factor(fullmoon$Month, levels=c("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")) table(Month, fullmoon$Month) fullmoon$Month <- Month summary(fullmoon) plot(fullmoon$Admission~fullmoon$Month) plot(fullmoon$Admission~fullmoon$Moon) plot(fullmoon$Admission~as.numeric(fullmoon$Month), ylab="Admissions", xlab="Month", main="Admissions by month and moon") points(fullmoon$Admission[fullmoon$Moon=="Before"]~as.numeric(fullmoon$Month)[fullmoon$Moon=="Before"], pch=19, col="orange") points(fullmoon$Admission[fullmoon$Moon=="During"]~as.numeric(fullmoon$Month)[fullmoon$Moon=="During"], pch=19, col="firebrick") points(fullmoon$Admission[fullmoon$Moon=="After"]~as.numeric(fullmoon$Month)[fullmoon$Moon=="After"], pch=19, col="springgreen") legend(x="topleft", legend=levels(fullmoon$Moon), col=c("orange", "firebrick", "springgreen"), pch=19) ################ ## Cviceni 2 a 3 ################ model.0 <- lm(Admission~1, data=fullmoon) summary(model.0) confint(model.0) ################ ## Cviceni 4 a 5 ################ model.1 <- lm(Admission~Moon, data=fullmoon) summary(model.1) confint(model.1) # stredni hodnota poctu pacientu pred uplnkem a <- c(1, 0, 0) before.est <- t(a)%*%coefficients(model.1) # odhad before.ci <- t(a)%*%coefficients(model.1) + c(-1, 1)*qt(0.975, df=33)*sqrt(t(a)%*%vcov(model.1)%*%a) # konfidencni interval # stredni hodnota poctu pacientu behem uplnku a <- c(1, 1, 0) during.est <- t(a)%*%coefficients(model.1) # odhad during.ci <- t(a)%*%coefficients(model.1) + c(-1, 1)*qt(0.975, df=33)*sqrt(t(a)%*%vcov(model.1)%*%a) # konfidencni interval # stredni hodnota poctu pacientu po uplnku a <- c(1, 0, 1) after.est <- t(a)%*%coefficients(model.1) # odhad after.ci <- t(a)%*%coefficients(model.1) + c(-1, 1)*qt(0.975, df=33)*sqrt(t(a)%*%vcov(model.1)%*%a) # konfidencni interval plot(c(8, 16)~c(1, 3), xlab="Moon", ylab="Admissions", main="Estimated mean admissions by moon", type="n", xaxt="n") legend(x="topleft", legend=levels(fullmoon$Moon), col=c("orange", "firebrick", "springgreen"), pch=19) points(1, before.est, pch=19, col="orange") points(2, during.est, pch=19, col="firebrick") points(3, after.est, pch=19, col="springgreen") arrows(x0=1, y0=before.ci[1], x1=1, y1=before.ci[2], lty=2, col="orange", code=3, angle=90, length=0.13) arrows(x0=2, y0=during.ci[1], x1=2, y1=during.ci[2], lty=2, col="firebrick", code=3, angle=90, length=0.13) arrows(x0=3, y0=after.ci[1], x1=3, y1=after.ci[2], lty=2, col="springgreen", code=3, angle=90, length=0.13) # test hypotezy o vlivu uplnku anova(model.0, model.1) anova(model.1)