## R Console from Martian Alphabet activity 3/10/22 > prop <- 9/13 > prop [1] 0.6923077 > library(tidyverse) Registered S3 methods overwritten by 'dbplyr': method from print.tbl_lazy print.tbl_sql ── Attaching packages ─────────────────────────────────────────────── tidyverse 1.3.1 ── ✓ ggplot2 3.3.5 ✓ purrr 0.3.4 ✓ tibble 3.1.6 ✓ dplyr 1.0.8 ✓ tidyr 1.1.4 ✓ stringr 1.4.0 ✓ readr 2.1.2 ✓ forcats 0.5.1 ── Conflicts ────────────────────────────────────────────────── tidyverse_conflicts() ── x dplyr::filter() masks stats::filter() x dplyr::lag() masks stats::lag() > ?geom_bar > ?rep > rep( c("correct", "incorrect"), c(9, 4) ) [1] "correct" "correct" "correct" "correct" "correct" "correct" [7] "correct" "correct" "correct" "incorrect" "incorrect" "incorrect" [13] "incorrect" > martian <- data.frame( + outcome <- rep( c("correct", "incorrect"), c(9, 4) ) + ) > View(martian) > martian <- data.frame( + outcome = rep( c("correct", "incorrect"), c(9, 4) ) + ) > View(martian) > ggplot(data = martian, aes(x = outcome)) + + geom_bar() > ggplot(data = martian, aes(x = outcome)) + + geom_bar() + + labs(x = "Student Answer", y = "Frequency", + title = "Proportion of Class Guessing Correct or Incorrect", + subtitle = "Martian Alphabet") > ggplot(data = martian, aes(x = outcome)) + + geom_bar() + + labs(x = "Student Answer", y = "Frequency", + title = "Proportion of Class Guessing Correct or Incorrect", + subtitle = "Martian Alphabet") > ggplot(data = martian, aes(x = outcome)) + + geom_bar(color = "purple") + + labs(x = "Student Answer", y = "Frequency", + title = "Proportion of Class Guessing Correct or Incorrect", + subtitle = "Martian Alphabet") > ggplot(data = martian, aes(x = outcome)) + + geom_bar(fill = "purple") + + labs(x = "Student Answer", y = "Frequency", + title = "Proportion of Class Guessing Correct or Incorrect", + subtitle = "Martian Alphabet") > ggplot(data = martian, aes(x = outcome)) + + geom_bar(fill = "purple") + + labs(x = "Student Answer", y = "Frequency", + title = "Frequency of Class Guessing Correct or Incorrect", + subtitle = "Martian Alphabet") > martian_sum <- data.frame( + outcome = c("correct", "incorrect"), + proportion = c(9/13, 4/13) + ) > View(martian_sum) > martian_sum <- data.frame( + outcome = c("correct", "incorrect"), + proportion = c(9/13, 4/13) + ) > ggplot(data = martian, aes(x = outcome, y = proportion)) + + geom_col(fill = "purple") + + labs(x = "Student Answer", y = "Frequency", + title = "Proportion of Class Guessing Correct or Incorrect", + subtitle = "Martian Alphabet") Error in FUN(X[[i]], ...) : object 'proportion' not found > ggplot(data = martian_sum, aes(x = outcome, y = proportion)) + + geom_col(fill = "purple") + + labs(x = "Student Answer", y = "Frequency", + title = "Proportion of Class Guessing Correct or Incorrect", + subtitle = "Martian Alphabet") > ggplot(data = martian, aes(x = outcome)) + + geom_bar(fill = "purple") + + scale_y_continuous(label = scales::percent()) + + labs(x = "Student Answer", y = "Frequency", + title = "Frequency of Class Guessing Correct or Incorrect", + subtitle = "Martian Alphabet") Error in number(x = x, accuracy = accuracy, scale = scale, prefix = prefix, : argument "x" is missing, with no default > ggplot(data = martian, aes(x = outcome)) + + geom_bar(fill = "purple") + + scale_y_continuous(label = scales::percent) + + labs(x = "Student Answer", y = "Frequency", + title = "Frequency of Class Guessing Correct or Incorrect", + subtitle = "Martian Alphabet") > ggplot(data = martian, aes(x = outcome)) + + geom_bar(aes(y = ..prop.., group = 1), fill = "purple") + + labs(x = "Student Answer", y = "Frequency", + title = "Frequency of Class Guessing Correct or Incorrect", + subtitle = "Martian Alphabet") > ?sample > sample(c("correct", "incorrect"), size = 1, prob = c(0.5, 0.5)) [1] "incorrect" > sample(c("correct", "incorrect"), size = 1, prob = c(0.5, 0.5)) [1] "correct" > sample(c("correct", "incorrect"), size = 1, prob = c(0.5, 0.5)) [1] "incorrect" > sample(c("correct", "incorrect"), size = 1, prob = c(0.5, 0.5)) [1] "correct" > sample(c("correct", "incorrect"), size = 1, prob = c(0.5, 0.5)) [1] "correct" > sample(c("correct", "incorrect"), size = 1, prob = c(0.5, 0.5)) [1] "correct" > sample(c("correct", "incorrect"), size = 1, prob = c(0.5, 0.5)) [1] "correct" > sample(c("correct", "incorrect"), size = 1, prob = c(0.5, 0.5)) [1] "correct" > sample(c("correct", "incorrect"), size = 1, prob = c(0.5, 0.5)) [1] "incorrect" > sample(c("correct", "incorrect"), size = 1, prob = c(0.5, 0.5)) [1] "incorrect" > sample(c("correct", "incorrect"), size = 1, prob = c(0.5, 0.5)) [1] "correct" > 13*.5 [1] 6.5 > sample(c("correct", "incorrect"), size = 13, prob = c(0.5, 0.5)) Error in sample.int(length(x), size, replace, prob) : cannot take a sample larger than the population when 'replace = FALSE' > sample(c("correct", "incorrect"), size = 13, prob = c(0.5, 0.5), replace = TRUE) [1] "correct" "incorrect" "incorrect" "incorrect" "correct" "incorrect" [7] "incorrect" "correct" "incorrect" "correct" "correct" "incorrect" [13] "incorrect" > x <- sample(c("correct", "incorrect"), size = 13, prob = c(0.5, 0.5), replace = TRUE) > x %>% count() Error in UseMethod("count") : no applicable method for 'count' applied to an object of class "character" > x [1] "correct" "correct" "correct" "incorrect" "incorrect" "incorrect" [7] "correct" "correct" "incorrect" "incorrect" "correct" "incorrect" [13] "incorrect" > data.frame(x) %>% count() > data.frame(x) %>% group_by(x) %>% count() > ifelse(x == "correct", 1, 0) [1] 1 1 1 0 0 0 1 1 0 0 1 0 0 > mean(ifelse(x == "correct", 1, 0)) [1] 0.4615385 > x == "correct" [1] TRUE TRUE TRUE FALSE FALSE FALSE TRUE TRUE FALSE FALSE TRUE FALSE FALSE > for(i in 1:10){ + x <- sample(c("correct", "incorrect"), + size = 13, prob = c(0.5, 0.5), replace = TRUE) + mean(x == "correct") + } > ?vector > sim_props <- vector("numeric", 1000) > length(sim_props) [1] 1000 > head(sim_props) [1] 0 0 0 0 0 0 > sim_props <- vector("numeric", 1000) > i = 1 > x <- sample(c("correct", "incorrect"), + size = 13, prob = c(0.5, 0.5), replace = TRUE) > sim_props[i] <- mean(x == "correct") > sim_props [1] 0.5384615 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [8] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [15] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [22] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [29] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [36] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [43] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [50] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [57] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [64] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [71] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [78] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [85] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [92] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [99] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [106] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [113] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [120] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [127] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [134] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [141] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [148] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [155] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [162] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [169] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [176] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [183] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [190] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [197] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [204] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [211] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [218] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [225] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [232] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [239] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [246] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [253] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [260] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [267] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [274] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [281] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [288] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [295] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [302] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [309] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [316] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [323] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [330] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [337] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [344] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [351] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [358] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [365] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [372] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [379] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [386] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [393] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [400] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [407] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [414] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [421] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [428] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [435] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [442] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [449] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [456] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [463] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [470] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [477] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [484] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [491] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [498] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [505] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [512] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [519] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [526] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [533] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [540] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [547] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [554] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [561] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [568] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [575] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [582] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [589] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [596] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [603] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [610] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [617] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [624] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [631] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [638] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [645] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [652] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [659] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [666] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [673] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [680] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [687] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [694] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [701] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [708] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [715] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [722] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [729] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [736] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [743] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [750] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [757] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [764] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [771] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [778] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [785] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [792] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [799] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [806] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [813] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [820] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [827] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [834] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [841] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [848] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [855] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [862] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [869] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [876] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [883] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [890] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [897] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [904] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [911] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [918] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [925] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [932] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [939] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [946] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [953] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [960] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [967] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [974] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [981] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [988] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [995] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 > i = 2 > x <- sample(c("correct", "incorrect"), + size = 13, prob = c(0.5, 0.5), replace = TRUE) > sim_props[i] <- mean(x == "correct") > head(sim_props) [1] 0.5384615 0.3846154 0.0000000 0.0000000 0.0000000 0.0000000 > i = 3 > x <- sample(c("correct", "incorrect"), + size = 13, prob = c(0.5, 0.5), replace = TRUE) > sim_props[i] <- mean(x == "correct") > head(sim_props) [1] 0.5384615 0.3846154 0.6153846 0.0000000 0.0000000 0.0000000 > for(i in 1:1000){ + x <- sample(c("correct", "incorrect"), + size = 13, prob = c(0.5, 0.5), replace = TRUE) + sim_props[i] <- mean(x == "correct") + } > head(sim_props) [1] 0.4615385 0.5384615 0.4615385 0.6923077 0.5384615 0.5384615 > tail(sim_props) [1] 0.4615385 0.3076923 0.5384615 0.6153846 0.7692308 0.8461538 > hist(sim_props) > dotplot(sim_props) Error in dotplot(sim_props) : could not find function "dotplot" > ?dotplot > head(data.frame(sim_props)) sim_props 1 0.4615385 2 0.5384615 3 0.4615385 4 0.6923077 5 0.5384615 6 0.5384615 > data.frame(sim_props) %>% ggplot(aes(x = sim_props)) + + geom_dotplot() Bin width defaults to 1/30 of the range of the data. Pick better value with `binwidth`. > data.frame(sim_props) %>% ggplot(aes(x = sim_props)) + + geom_dotplot(dotsize = 0.5) Bin width defaults to 1/30 of the range of the data. Pick better value with `binwidth`. > data.frame(sim_props) %>% ggplot(aes(x = sim_props)) + + geom_dotplot(dotsize = 0.3) Bin width defaults to 1/30 of the range of the data. Pick better value with `binwidth`. > data.frame(sim_props) %>% ggplot(aes(x = sim_props)) + + geom_dotplot(dotsize = 0.1) Bin width defaults to 1/30 of the range of the data. Pick better value with `binwidth`. > data.frame(sim_props) %>% ggplot(aes(x = sim_props)) + + geom_dotplot(dotsize = 0.08) Bin width defaults to 1/30 of the range of the data. Pick better value with `binwidth`. > 9/13 [1] 0.6923077 > p_value <- function(x, n, reps = 1000){ + # x = number of correct guesses in observed data + # n = sample size + # reps = number of simulated classes + sim_props <- NULL + for(i in 1:reps){ + my_samp <- sample(c("correct", "incorrect"), + size = n, prob = c(0.5, 0.5), replace = TRUE) + sim_props[i] <- mean(x == "correct") + } + return( mean(sim_props >= x/n) ) + } > p_value(9, 13) [1] 0 > p_value(9, 13) [1] 0 > p_value(9, 13) [1] 0 > pbinom(8, 13, prob = 0.5, lower.tail=FALSE) [1] 0.1334229 > p_value <- function(x, n, reps = 1000){ + # x = number of correct guesses in observed data + # n = sample size + # reps = number of simulated classes + sim_props <- NULL + for(i in 1:reps){ + my_samp <- sample(c("correct", "incorrect"), + size = n, prob = c(0.5, 0.5), replace = TRUE) + sim_props[i] <- mean(my_samp == "correct") + } + return( mean(sim_props >= x/n) ) + } > p_value(9, 13) [1] 0.156 > p_value(9, 13) [1] 0.129 > p_value(9, 13) [1] 0.129 > p_value(9, 13, reps = 10000) [1] 0.1387