This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(purrr); library(stringr) | |
map_chr(str_split(df$col2, ", "), 1) # the number indicates the vec you want based on the split |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pacman::p_load(data.table, stringr) | |
setDT(ct) | |
col_fence.s <- c("col1", "col2", "col3") | |
ct[,(str_c(col_fence.s, ".s")) := lapply(.SD, function(x) as.numeric(scale(x))), .SDcols=col_fence.s] # making new ones with a .s suffex |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pl1 <- ggplot(df, aes(x)) + | |
geom_rect(aes(xmin = .8, xmax = 1.2, ymin = 0, ymax = 0.4, fill = "lightblue", alpha = .3)) + | |
stat_function(fun = dnorm, n = 200, args = list(mean = 0, sd = 1)) + | |
#geom_density(color = "darkblue", size = 1) + | |
theme_minimal(base_size = 12) + | |
theme(legend.position = "none") + | |
labs(y = "Density of participants (n = 200)", x = "Ability on a Task (SD)") + | |
scale_x_continuous(breaks = c(-3, -2, -1, 0, 1, 2, 3), limits = c(-3.5, 3.5)) | |
ggsave("~/Desktop/abilitychallange_s1.png", pl1, bg = "white", width = 8, height = 4) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Nicholas Judd | Donders Institute | |
# 26-12-2022 | |
# njudd.com | |
# replicating https://twitter.com/rogierK/status/1004443199031607296/photo/2 | |
# Wagenmakers, E.-J., & Farrell, S. (2004). | |
# AIC model selection using Akaike weights. | |
# Psychonomic Bulletin & Review, 11(1), 192–196. | |
if (!require(pacman)){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
iris |> | |
(\(.) {head(.)})() | |
# or an example with plotting | |
diamonds |> (\(.) { | |
ggplot(., aes(carat, price)) + geom_point() | |
}) () #https://stackoverflow.com/questions/73752006/using-the-base-r-pipe-to-pipe-ggplot2-to-plotly |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# No need to call Bill Gates! | |
# here is how you get correlation tables by group with their p-val matries and even plot them | |
library(Hmisc); library(tidyverse); library(corrplot) | |
result <- iris |> # base R pipe | |
#select() # remove col's you don't want in the correlation matrix | |
group_by(Species) |> # grouping col | |
group_map(~rcorr(as.matrix(.))) |> | |
setNames(unique(sort(iris$Species))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Trying to figure out what R is doing with anova's | |
# The difference of aov() and lm() simply changes how summary() acts | |
# summary(aov()) is the same as anova(lm(), which are both TYPE 1! | |
# for type = III SS you need to use Anova in the library(car) package | |
# https://rcompanion.org/rcompanion/d_04.html | |
# Different SS primer | |
# https://stats.stackexchange.com/questions/20452/how-to-interpret-type-i-type-ii-and-type-iii-anova-and-manova/20455#20455 |