library(LM2GLMM) knitr::opts_chunk$set(cache = FALSE, fig.align = "center", fig.width = 4, fig.height = 4, cache.path = "./cache_knitr/LM_intro_ex/", fig.path = "./fig_knitr/LM_intro_ex/") options(width = 200) set.seed(1L)
Compute the following equation:
Using the dataset TitanicSurvival
, figure out:
dim(TitanicSurvival) str(TitanicSurvival) apply(TitanicSurvival, 2, function(x) any(is.na(x))) focus <- with(TitanicSurvival, survived[sex == "female" & !is.na(age) & age < 20 & passengerClass == "2nd"]) table(focus, useNA = "always")
The following function can be used to investigate the statistical power of a t-test (i.e. the probability to detect a significant effect when there really is one = rate of true positive):
compare_heights <- function(n_group = 10, height_difference = 5) { male <- rnorm(n = n_group, mean = 180, sd = 6) female <- rnorm(n = n_group, mean = 180 - height_difference, sd = 6) t_test_res <- t.test(male, female) t_test_res$p.value } N <- seq(from = 10, to = 60, by = 2) power <- sapply(N, function(n) mean(replicate(100, compare_heights(n_group = n)) <= 0.05)) plot(power ~ N)
Can you run, read and understand this code?
Using the dataset TitanicSurvival
, find a good way to show in one plot what influenced the survival of passengers.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.