ggtitle("Instructor's pacing within allotted time (n = 204)") +
geom_text(aes(y = ypos, label = group), color = "black", size=5) +
scale_fill_brewer(palette="Set1")
source("D:/work/statistics_workshop/external_analyses/workshops/summarize_feedback.r")
source("D:/work/statistics_workshop/external_analyses/workshops/summarize_feedback.r")
rstudioapi::getActiveDocumentContext()$path
install.packages("rstudioapi")
setwd(dirname(rstudioapi::getActiveDocumentContext()$path))
x <- c("1 - Excellent", "2 - Good", "3 - Fair", "4 - Poor")
y <- table(cln$`Instructor's pacing within allotted time`)
data <- data.frame(group = x, value = as.numeric(y))
library(dplyr)
data <- data %>%
arrange(desc(group)) %>%
mutate(prop = value / sum(data$value) *100) %>%
mutate(ypos = cumsum(prop)- 0.5*prop )
# Basic piechart
g1 <- ggplot(data, aes(x="", y=prop, fill=group)) +
geom_bar(stat="identity", width=1.0, color="white") +
coord_polar("y", start=0) +
theme_void() +
theme(legend.position="none") +
ggtitle("Instructor's pacing within allotted time (n = 204)") +
geom_text(aes(y = ypos, label = group), color = "black", size=5) +
scale_fill_brewer(palette="Set1")
ggsave("./plots/01_piechart", g1, width = 4, height = 4)
# Basic piechart
g1 <- ggplot(data, aes(x="", y=prop, fill=group)) +
geom_bar(stat="identity", width=1.0, color="white") +
coord_polar("y", start=0) +
theme_void() +
theme(legend.position="none") +
ggtitle("Instructor's pacing within allotted time (n = 204)") +
geom_text(aes(y = ypos, label = group), color = "black", size=5) +
scale_fill_brewer(palette="Set1")
ggsave("./plots/01_piechart.png", g1, width = 4, height = 4)
# Basic piechart
g1 <- ggplot(data, aes(x="", y=prop, fill=group)) +
geom_bar(stat="identity", width=1.0, color="white") +
coord_polar("y", start=0) +
theme_void() +
theme(legend.position="none") +
ggtitle("Instructor's pacing within allotted time (n = 204)") +
geom_text(aes(y = ypos, label = group), color = "black", size=5) +
scale_fill_brewer(palette="Set1")
ggsave("../../plots/01_piechart.png", g1, width = 4, height = 4)
source("D:/work/statistics_workshop/external_analyses/workshops/summarize_feedback.r")
source("D:/work/statistics_workshop/external_analyses/workshops/summarize_feedback.r")
cls
cln
tapply(cln$Overall, cln$ID, mean)
x <- tapply(cln$Overall, cln$ID, mean)
y <- tapply(cln$Overall, cln$ID, count)
y <- tapply(cln$Overall, cln$ID, length)
x
y
cor(x, y)
cor.test(x, y)
plot(x, y)
ggplot(df, aes(score, size)) + geom_point() + geom_smooth(method = "lm")
plot
score <- tapply(cln$Overall, cln$ID, mean)
size  <- tapply(cln$Overall, cln$ID, count)
df <- data.frame(score, size)
ggplot(df, aes(score, size)) + geom_point() + geom_smooth(method = "lm")
df
score
score <- tapply(cln$Overall, cln$ID, mean)
size  <- tapply(cln$Overall, cln$ID, count)
df <- data.frame(score = score, size = size)
ggplot(df, aes(score, size)) + geom_point() + geom_smooth(method = "lm")
score <- tapply(cln$Overall, cln$ID, mean)
size  <- tapply(cln$Overall, cln$ID, length)
df <- data.frame(score = score, size = size)
ggplot(df, aes(score, size)) + geom_point() + geom_smooth(method = "lm")
score <- tapply(cln$Overall, cln$ID, mean)
size  <- tapply(cln$Overall, cln$ID, length)
df <- data.frame(score = score, size = size)
ggplot(df, aes(score, size)) + geom_point() + geom_smooth(method = "lm", SE = NA)
score <- tapply(cln$Overall, cln$ID, mean)
size  <- tapply(cln$Overall, cln$ID, length)
df <- data.frame(score = score, size = size)
ggplot(df, aes(score, size)) + geom_point() + geom_smooth(method = "lm", se = NA)
score <- tapply(cln$Overall, cln$ID, mean)
size  <- tapply(cln$Overall, cln$ID, length)
df <- data.frame(score = score, size = size)
ggplot(df, aes(score, size)) + geom_point() + geom_smooth(method = "lm", se = NULL)
score <- tapply(cln$Overall, cln$ID, mean)
size  <- tapply(cln$Overall, cln$ID, length)
df <- data.frame(score = score, size = size)
ggplot(df, aes(score, size)) + geom_point() + geom_abline()
ggplot(df, aes(score, size)) + geom_point() + geom_smooth(method = "lm", SE = NULL)
?geom_smooth
ggplot(df, aes(score, size)) + geom_point() + geom_smooth(method = "lm", se = FALSE)
ggplot(df, aes(size, score)) + geom_point() + geom_smooth(method = "lm", se = FALSE) +
xlab("number of participants") + ylab("average overall score")
g1 <- ggplot(df, aes(size, score)) + geom_point() + geom_smooth(method = "lm", se = FALSE) +
xlab("number of participants") + ylab("average overall score")
ggsave("../../plots/01_scatterplot.png", g1, width = 4, height = 4)
score <- tapply(cln$Overall, cln$ID, mean)
size  <- tapply(cln$Overall, cln$ID, length)
df <- data.frame(score = score, size = size)
g1 <- ggplot(df, aes(size, score)) + geom_point() + geom_smooth(method = "lm", se = FALSE) +
xlab("number of participants") + ylab("average overall score")
ggsave("../../plots/01_scatterplot.png", g1, width = 4, height = 4)
score
size
# Barchart
df <- data.frame(ID = 1:16, size = size)
g1 <- ggplot(df, aes(ID, size)) + geom_point() + geom_smooth(method = "lm", se = FALSE) +
xlab("number of participants") + ylab("average overall score")
ggsave("../../plots/01_boxplot-participants.png", g1, width = 8, height = 4)
# Barchart
df <- data.frame(ID = 1:16, size = size)
g1 <- ggplot(df, aes(ID, size)) + geom_bar(stat = "identity") +
xlab("number of participants") + ylab("average overall score")
ggsave("../../plots/01_boxplot-participants.png", g1, width = 8, height = 4)
# Barchart
df <- data.frame(ID = 1:16, size = size)
g1 <- ggplot(df, aes(ID, size)) + geom_bar(stat = "identity") +
xlab("workshop ID") + ylab("number of participants")
ggsave("../../plots/01_boxplot-participants.png", g1, width = 8, height = 4)
df <- data.frame(ID = 1:16, size = size)
g1 <- ggplot(df, aes(ID, size)) + geom_bar(stat = "identity") +
xlab("workshop ID") + ylab("number of participants") +
geom_hline(yintercept = mean(df$size), colour = "red", lty = "dashed")
ggsave("../../plots/01_boxplot-participants.png", g1, width = 8, height = 4)
# Barchart
df <- data.frame(ID = 1:16, size = size)
g1 <- ggplot(df, aes(ID, size)) + geom_bar(stat = "identity") +
xlab("workshop ID") + ylab("number of participants") +
geom_hline(yintercept = mean(df$size), colour = "red", lty = "dashed")
ggsave("../../plots/01_boxplot-participants.png", g1, width = 6, height = 4)
score_all <- table(cln$Overall) / nrow(cln$Overall)
score_all <- table(cln$Overall) / nrow(cln$Overall)
score_All
score_all
table(cln$Overall)
nrow(cln$Overall)
table(cln$Overall) / length(cln$Overall)
score_all <- table(cln$`Instructor's pacing within allotted time`) / length(cln$`Instructor's pacing within allotted time`)
score_All
score_all
table(x[cln$ID != 5]) / length(x[cln$ID != 5])
x <- cln$`Instructor's pacing within allotted time`
x
table(x[cln$ID != 5])
table(x[cln$ID != 5]) / length(x[cln$ID != 5])
score_all <- table(x[cln$ID != 5]) / length(x[cln$ID != 5])
score_one <- table(x[cln$ID == 5]) / length(x[cln$ID == 5])
score_one
score_one
table(x[cln$ID == 5]) / length(x[cln$ID == 5])
table(x[cln$ID != 5]) / length(x[cln$ID != 5])
# Barchart 2
x <- cln$`Instructor's pacing within allotted time`
score_all <- table(x[cln$ID != 5]) / length(x[cln$ID != 5])
score_one <- table(x[cln$ID == 5]) / length(x[cln$ID == 5])
x <- c("1 - Excellent", "2 - Good", "3 - Fair", "4 - Poor")
df <- data.frame(count = c(score_one, score_all), grade = rep(x, 2), group = rep(c("instructor", "overall"), each = 4))
df
c(score_one, score_all)
ggplot(df, aes(grade, count)) + geom_bar(stat = "identity")
ggplot(df, aes(grade, count, fill = group)) + geom_bar(stat = "identity") +
xlab("grade") + ylab("%")
ggplot(df, aes(grade, count, fill = group)) + geom_bar(stat = "identity") +
xlab("grade") + ylab("%") +
ggtitle("Instructor's pacing within allotted time (n = 204)")
length(x[cln$ID != 5])
length(x[cln$ID == 5])
g1 <- ggplot(df, aes(grade, count, fill = group)) + geom_bar(stat = "identity") +
xlab("grade") + ylab("%") +
ggtitle("Instructor's pacing within allotted time (n = 192, 12)")
ggsave("../../plots/01_barchart-instructor.png", g1, width = 6, height = 4)
g1 <- ggplot(df, aes(grade, count, fill = group)) + geom_bar(stat = "identity", position = "dodge") +
xlab("grade") + ylab("%") +
ggtitle("Instructor's pacing within allotted time (n = 192, 12)")
g1
source("D:/work/statistics_workshop/external_analyses/workshops/summarize_feedback.r")
cln[1,]
cln <- cln[, c(1, 2, 6)]
setwd(dirname(rstudioapi::getActiveDocumentContext()$path))
## Piechart
x <- c("1 - Excellent", "2 - Good", "3 - Fair", "4 - Poor")
y <- table(cln$`Instructor's pacing within allotted time`)
data <- data.frame(group = x, value = as.numeric(y))
library(dplyr)
data <- data %>%
arrange(desc(group)) %>%
mutate(prop = value / sum(data$value) *100) %>%
mutate(ypos = cumsum(prop)- 0.5*prop )
# Basic piechart
g1 <- ggplot(data, aes(x="", y=prop, fill=group)) +
geom_bar(stat="identity", width=1.0, color="white") +
coord_polar("y", start=0) +
theme_void() +
theme(legend.position="none") +
ggtitle("Instructor's pacing within allotted time (n = 204)") +
geom_text(aes(y = ypos, label = group), color = "black", size = 2.5) +
scale_fill_brewer(palette="Set1")
ggsave("../../plots/01_piechart.png", g1, width = 4, height = 4)
## Scatterplot
score <- tapply(cln$Overall, cln$ID, mean)
size  <- tapply(cln$Overall, cln$ID, length)
df <- data.frame(score = score, size = size)
g1 <- ggplot(df, aes(size, score)) + geom_point() + geom_smooth(method = "lm", se = FALSE) +
xlab("number of participants") + ylab("average overall score")
ggsave("../../plots/01_scatterplot.png", g1, width = 4, height = 4)
# Barchart
df <- data.frame(ID = 1:16, size = size)
g1 <- ggplot(df, aes(ID, size)) + geom_bar(stat = "identity") +
xlab("workshop ID") + ylab("number of participants") +
geom_hline(yintercept = mean(df$size), colour = "red", lty = "dashed")
ggsave("../../plots/01_barchart-participants.png", g1, width = 6, height = 4)
# Barchart 2
x <- cln$`Instructor's pacing within allotted time`
score_all <- table(x[cln$ID != 5]) / length(x[cln$ID != 5])
score_one <- table(x[cln$ID == 5]) / length(x[cln$ID == 5])
x <- c("1 - Excellent", "2 - Good", "3 - Fair", "4 - Poor")
df <- data.frame(count = c(score_one, score_all), grade = rep(x, 2), group = rep(c("instructor", "overall"), each = 4))
g1 <- ggplot(df, aes(grade, count, fill = group)) + geom_bar(stat = "identity", position = "dodge") +
xlab("grade") + ylab("%") +
ggtitle("Instructor's pacing within allotted time (n = 192, 12)")
ggsave("../../plots/01_barchart-instructor.png", g1, width = 6, height = 4)
cln
readPNG
?readPNG
??readPNG
install.packages("png")
# READ DATA
ffs <- list.files("./feedback_data/", full.names = T)
ffs <- ffs[!file.info(ffs)$isdir]
all = NULL
for (ff in ffs) {
print(ff)
dat <- read.csv(ff, h = F, sep = ";", colClasses = "character")
all <- rbind(all, data.frame(ws = ff, dat))
}
cln <- NULL
for (i in 1:nrow(all)) {
rw  <- all[i,]
x1  <- strsplit(rw$V1, "", fix = T)[[1]]
x2  <- strsplit(rw$V2, "", fix = T)[[1]]
x3  <- strsplit(rw$V3, "", fix = T)[[1]]
cln <- rbind(cln, data.frame(rw[,1], t(as.numeric(c(x1, x2, x3)))))
}
nms <- c("ID", "Overall",
"Instructor's knowledge",
"Instructor's communication",
"Instructor's preparation/materials",
"Instructor's pacing within allotted time",
"How useful was the topic",
"Did the topic match what was advertised",
"Event organisation", "too long",
"too short", "worth the cost", "not worth the cost", "enjoyable",
"not enjoyable", "useful", "not useful", "too basic",
"too advanced", "interesting", "boring", "informative",
"I would attend other workshops/tutorials by this instructor.",
"I would attend advanced workshops/tutorials on this topic.",
"I would attend other events by DataScience@UL-FRI.",
"I would recommend DataScience@UL-FRI events to others.")
names(cln) <- nms
cln$ID <- as.numeric(factor(cln$ID))
cln <- cln[complete.cases(cln),]
cln <- cln[, c(1, 2, 6)]
setwd(dirname(rstudioapi::getActiveDocumentContext()$path))
## Piechart
x <- c("1 - Excellent", "2 - Good", "3 - Fair", "4 - Poor")
y <- table(cln$`Instructor's pacing within allotted time`)
data <- data.frame(group = x, value = as.numeric(y))
library(dplyr)
data <- data %>%
arrange(desc(group)) %>%
mutate(prop = value / sum(data$value) *100) %>%
mutate(ypos = cumsum(prop)- 0.5*prop )
# Basic piechart
g1 <- ggplot(data, aes(x="", y=prop, fill=group)) +
geom_bar(stat="identity", width=1.0, color="white") +
coord_polar("y", start=0) +
theme_void() +
theme(legend.position="none") +
ggtitle("Instructor's pacing within allotted time (n = 204)") +
geom_text(aes(y = ypos, label = group), color = "black", size = 2.5) +
scale_fill_brewer(palette="Set1")
ggsave("../../plots/01_piechart.png", g1, width = 4, height = 4)
## Scatterplot
score <- tapply(cln$Overall, cln$ID, mean)
size  <- tapply(cln$Overall, cln$ID, length)
df <- data.frame(score = score, size = size)
size
mean(size)
library(callr)
cls
lln
cln
# Barchart 2
x <- cln$`Instructor's pacing within allotted time`
source("D:/work/statistics_workshop/external_analyses/workshops/summarize_feedback.r")
knitr::opts_chunk$set(echo = TRUE)
df <- read.table("./data/workshops.csv", h = T, sep = ";")
df
df <- read.table("./data/workshops.csv", h = T, sep = ";")
x  <- table(df$ID) # number of participants
x
df <- read.table("./data/workshops.csv", h = T, sep = ";")
x  <- table(df$ID) # number of participants
t.test(x, mu = 12)
24 * 48
35 * 48
setwd(dirname(rstudioapi::getActiveDocumentContext()$path))
source("D:/work/statistics_workshop/R_code/intro_plots.r")
source("D:/work/statistics_workshop/R_code/intro_plots.r")
cln <- read.table("../data/workshops.csv", sep = ";", h = T)
cln
source("D:/work/statistics_workshop/R_code/intro_plots.r")
library(dplyr)
library(ggplot2)
setwd(dirname(rstudioapi::getActiveDocumentContext()$path))
cln <- read.table("../data/workshops.csv", sep = ";", h = T)
## Piechart
x <- c("1 - Excellent", "2 - Good", "3 - Fair", "4 - Poor")
y <- table(cln$`Instructor's pacing within allotted time`)
data <- data.frame(group = x, value = as.numeric(y))
source("D:/work/statistics_workshop/R_code/intro_plots.r")
source("D:/work/statistics_workshop/R_code/intro_plots.r")
source("D:/work/statistics_workshop/R_code/intro_plots.r")
ggplot(df, aes(ID, size)) + geom_bar(stat = "identity") +
xlab("workshop ID") + ylab("number of participants") +
geom_hline(yintercept = mean(df$size), colour = "red", lty = "dashed") +
annotate("text", x = 10, y = 10, paste0("average = ", mean(df$size)))
df <- data.frame(ID = 1:16, size = size)
g1 <- ggplot(df, aes(ID, size)) + geom_bar(stat = "identity") +
xlab("workshop ID") + ylab("number of participants") +
geom_hline(yintercept = mean(df$size), colour = "red", lty = "dashed") +
annotate("text", x = 10, y = 10, paste0("average = ", mean(df$size)))
ggsave("../plots/01_barchart-participants.png", g1, width = 6, height = 4)
ggplot(df, aes(ID, size)) + geom_bar(stat = "identity") +
xlab("workshop ID") + ylab("number of participants") +
geom_hline(yintercept = mean(df$size), colour = "red", lty = "dashed") +
annotate("text", x = 10, y = 10, paste0("average = ", mean(df$size)))
df <- data.frame(ID = 1:16, size = size)
g1 <- ggplot(df, aes(ID, size)) + geom_bar(stat = "identity") +
xlab("workshop ID") + ylab("number of participants") +
geom_hline(yintercept = mean(df$size), colour = "red", lty = "dashed")
g1
ggplot(df, aes(ID, size)) + geom_bar(stat = "identity") +
xlab("workshop ID") + ylab("number of participants") +
geom_hline(yintercept = mean(df$size), colour = "red", lty = "dashed") +
annotate("text", x = 10, y = 10, label = paste0("average = ", mean(df$size)))
ggplot(df, aes(ID, size)) + geom_bar(stat = "identity") +
xlab("workshop ID") + ylab("number of participants") +
geom_hline(yintercept = mean(df$size), colour = "red", lty = "dashed") +
annotate("text", x = 2, y =  mean(df$size), label = paste0("average = ", mean(df$size)))
ggplot(df, aes(ID, size)) + geom_bar(stat = "identity") +
xlab("workshop ID") + ylab("number of participants") +
geom_hline(yintercept = mean(df$size), colour = "red", lty = "dashed") +
annotate("text", x = 3, y =  1 + mean(df$size), label = paste0("average = ", mean(df$size)))
ggplot(df, aes(ID, size)) + geom_bar(stat = "identity") +
xlab("workshop ID") + ylab("number of participants") +
geom_hline(yintercept = mean(df$size), colour = "red", lty = "dashed") +
annotate("text", x = 3, y =  0.5 + mean(df$size), label = paste0("average = ", mean(df$size)))
ggplot(df, aes(ID, size)) + geom_bar(stat = "identity") +
xlab("workshop ID") + ylab("number of participants") +
geom_hline(yintercept = mean(df$size), colour = "red", lty = "dashed") +
annotate("text", x = 3, y =  0.5 + mean(df$size), colour = "red", label = paste0("average = ", mean(df$size)))
score <- tapply(cln$Overall, cln$ID, mean)
size  <- tapply(cln$Overall, cln$ID, length)
df <- data.frame(score = score, size = size)
g1 <- ggplot(df, aes(size, score)) + geom_point() + geom_smooth(method = "lm", se = FALSE) +
xlab("number of participants") + ylab("average overall score") +
annotate("text", x = 3, y =  0.5, colour = "red", label = paste0("cor. coeff. = ", round(cor(size, score), 2))))
score <- tapply(cln$Overall, cln$ID, mean)
size  <- tapply(cln$Overall, cln$ID, length)
df <- data.frame(score = score, size = size)
ggplot(df, aes(size, score)) + geom_point() + geom_smooth(method = "lm", se = FALSE) +
xlab("number of participants") + ylab("average overall score") +
annotate("text", x = 3, y =  0.5, colour = "red",
label = paste0("cor. coeff. = ", round(cor(df$size, df$score), 2))))
ggplot(df, aes(size, score)) + geom_point() + geom_smooth(method = "lm", se = FALSE) +
xlab("number of participants") + ylab("average overall score")
ggplot(df, aes(size, score)) + geom_point() + geom_smooth(method = "lm", se = FALSE) +
xlab("number of participants") + ylab("average overall score") +
annotate("text", x = 20, y =  1.7, colour = "red",
label = paste0("cor. coeff. = ", round(cor(df$size, df$score), 2))))
ggplot(df, aes(size, score)) + geom_point() + geom_smooth(method = "lm", se = FALSE) +
xlab("number of participants") + ylab("average overall score") +
annotate("text", x = 20, y =  1.7, colour = "red",
label = paste0("cor. coeff. = ", round(cor(df$size, df$score), 2)))
ggplot(df, aes(size, score)) + geom_point() + geom_smooth(method = "lm", se = FALSE) +
xlab("number of participants") + ylab("average overall score") +
annotate("text", x = 20, y =  1.7, colour = "red",
label = paste0("cor. coeff. = ", size = 7, round(cor(df$size, df$score), 2)))
ggplot(df, aes(size, score)) + geom_point() + geom_smooth(method = "lm", se = FALSE) +
xlab("number of participants") + ylab("average overall score") +
annotate("text", x = 20, y =  1.7, colour = "red",
label = paste0("cor. coeff. = ", size = 9, round(cor(df$size, df$score), 2)))
ggplot(df, aes(size, score)) + geom_point() + geom_smooth(method = "lm", se = FALSE) +
xlab("number of participants") + ylab("average overall score") +
annotate("text", x = 20, y =  1.7, colour = "red",
label = paste0("cor. coeff. = ", size = 9, round(cor(df$size, df$score), 2)))
ggplot(df, aes(size, score)) + geom_point() + geom_smooth(method = "lm", se = FALSE) +
xlab("number of participants") + ylab("average overall score") +
annotate("text", x = 20, y =  1.7, colour = "red",
label = paste0("cor. coeff. = ", round(cor(df$size, df$score), 2)))
source("D:/work/statistics_workshop/R_code/intro_plots.r")
source("D:/work/statistics_workshop/R_code/intro_plots.r")
setwd(dirname(rstudioapi::getActiveDocumentContext()$path))
df <- read.table("./data/workshops.csv", h = T, sep = ";")
# using classical t-test and CI
x  <- table(df$ID) # participants per workshop
t.test(x, mu = 12)
x
df
setwd(dirname(rstudioapi::getActiveDocumentContext()$path))
df <- read.table("./data/workshops.csv", h = T, sep = ";")
setwd(dirname(rstudioapi::getActiveDocumentContext()$path))
df <- read.table("../data/workshops.csv", h = T, sep = ";")
# using classical t-test and CI
x  <- table(df$ID) # participants per workshop
t.test(x, mu = 12)
1720 / 12
1720 / 12 * 0.3
source("D:/work/statistics_workshop/R_code/intro_plots.r")
source("D:/work/statistics_workshop/R_code/intro_plots.r")
source("D:/work/statistics_workshop/R_code/intro_plots.r")
setwd(dirname(rstudioapi::getActiveDocumentContext()$path))
df    <- read.table("../data/workshops.csv", h = T, sep = ";")
x     <- df$Instructor.s.pacing.within.allotted.time
x_avg <- tapply(score, df$ID, mean)
setwd(dirname(rstudioapi::getActiveDocumentContext()$path))
df    <- read.table("../data/workshops.csv", h = T, sep = ";")
x     <- df$Instructor.s.pacing.within.allotted.time
x_avg <- tapply(x, df$ID, mean)
x
x_avg
#### t-test & CI ---------------------------------------------------------------
t.test(x)
t.test(x_avg)
#### t-test & CI ---------------------------------------------------------------
t.test(x, 1.5, alt = "greater")
t.test(x_avg, alt = "greater")
#### t-test & CI ---------------------------------------------------------------
t.test(x, mu = 1.5, alt = "greater")
t.test(x_avg, mu = 1.5, alt = "greater")
source("D:/work/statistics_workshop/R_code/08_hierarchical_bootstrap.r")
#### 2-level bootstrap ---------------------------------------------------------
set.seed(1)
mus <- NULL
for (i in 1:m) {
# reasample workshops
idx <- sample((1:16), 16, rep = T)
tmp <- c()
# resample scores
for (j in idx) {
x_tmp <- df$Instructor.s.pacing.within.allotted.time[df$ID == j]
y <- c(tmp, mean(sample(x_tmp, length(x_tmp), rep = T)))
}
mus <- rbind(mus, mean(y))
}
quantile(mus, p = c(0.025, 0.975))
mus
mus
length(x)
length(x_avg)
source("D:/work/statistics_workshop/R_code/08_hierarchical_bootstrap.r")
quantile(mus, p = c(0.025, 0.975))
setwd(dirname(rstudioapi::getActiveDocumentContext()$path))
df    <- read.table("../data/workshops.csv", h = T, sep = ";")
x     <- df$Instructor.s.pacing.within.allotted.time
x_avg <- tapply(x, df$ID, mean)
#### t-test & CI ---------------------------------------------------------------
t.test(x, mu = 1.5, alt = "greater")
t.test(x_avg, mu = 1.5, alt = "greater")
quantile(mus, p = c(0.05, 1))
quantile(mus, p = c(0.05, 1))
x
res <- boot(x, function(data, idx) { mean(data[idx]) }, R = m)
boot.ci(res, type = "perc")
library(boot)
res <- boot(x, function(data, idx) { mean(data[idx]) }, R = m)
boot.ci(res, type = "perc")
res <- boot(x, function(data, idx) { mean(data[idx]) }, R = m)
boot.ci(res, type = "perc", c(0.05, +Inf))
res <- boot(x, function(data, idx) { mean(data[idx]) }, R = m)
boot.ci(res, type = "perc", c(0.9, 0.95))
setwd(dirname(rstudioapi::getActiveDocumentContext()$path))
df    <- read.table("../data/workshops.csv", h = T, sep = ";")
x     <- df$Instructor.s.pacing.within.allotted.time
x_avg <- tapply(x, df$ID, mean)
#### t-test & CI ---------------------------------------------------------------
t.test(x, mu = 1.5, alt = "greater")
t.test(x_avg, mu = 1.5, alt = "greater")
?boot.ci
res <- boot(x_avg, function(data, idx) { mean(data[idx]) }, R = m)
boot.ci(res, type = "perc", c(0.9, 0.95))
#### 2-level bootstrap ---------------------------------------------------------
set.seed(1)
m <- 1000
n <- length(x_avg)
mus <- NULL
for (i in 1:m) {
idx <- sample(1:n, n, rep = T)   # reasample workshops
tmp <- c()
for (j in idx) {   # resample scores
x_tmp <- x[df$ID == j]
z     <- sample(x_tmp, length(x_tmp), rep = T)
y     <- c(tmp, mean(z))
}
mus <- rbind(mus, mean(y))
}
quantile(mus, p = c(0.05, 1))
quantile(mus, p = c(0.05, 0.95))
