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('dplyr') | |
library('tidyr') | |
library('pbapply') | |
#' simulate() | |
#' | |
#' @param num_groups Number of groups | |
#' @param num_per_group Number of observations per group | |
#' @param true_coef The true `beta_1` in `Y_t ~ beta_0 + beta_1*X_t` | |
#' @param phi A function that takes Y_t-1,...,Y_t and returns Xt |
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(dplyr) | |
library(purrr) | |
library(broom) | |
# A Single Study: ---- | |
a_study <- function(effect_size_distr_function, main_n = 100, pilot_n = 0, pilot_effect_size_threshold = NULL) { | |
this_study_effect_size <- effect_size_distr_function() | |
pilot <- list(result_vec = rnorm(n = pilot_n, mean = this_study_effect_size, sd = 1), | |
occurred = pilot_n > 0) |
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('dplyr') | |
library('survival') | |
## Make the Data: ----- | |
set.seed(3) | |
n_sub <- 1000 | |
current_date <- 365*2 | |
true_shape <- 2 | |
true_scale <- 365 |
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
generate_markdown_for_site <- function(path_to_rmd, path_to_knit_to) { | |
filename <- basename(path_to_rmd) | |
message("Setting working directory to ", path_to_rmd) | |
setwd(dirname(path_to_rmd)) | |
post_name <- sub("^([^.]*).*", "\\1", filename) | |
content <- readLines(paste0(post_name, ".Rmd")) | |
render_markdown(strict=TRUE) | |
opts_knit$set(out.format='markdown') | |
opts_knit$set(base.dir= paste0(path_to_knit_to, "/", post_name,"/") ) | |
opts_knit$set(base.url= paste0("/static/",post_name,"/") ) |
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
fitgamma <- function(x) { | |
# Equivalent to `MASS::fitdistr(x, densfun = "gamma")`, where x are first rescaled to | |
# the appropriate scale for a gamma distribution. Useful for fitting the gamma distribution to | |
# data which, when multiplied by a constant, follows this distribution | |
if (!requireNamespace("MASS")) stop("Requires MASS package.") | |
fit <- glm(formula = x ~ 1, family = Gamma) | |
out <- MASS::fitdistr(x * coef(fit), "gamma") | |
out$scaling_multiplier <- unname(coef(fit)) | |
out |
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
# load *eyetrackingR* and set data options | |
library(eyetrackingR) | |
data("word_recognition") | |
dataset <- make_eyetrackingr_data(word_recognition, | |
participant_column = "ParticipantName", | |
trial_column = "Trial", | |
time_column = "TimeFromTrialOnset", | |
trackloss_column = "TrackLoss", | |
aoi_columns = c('Animate','Inanimate'), | |
treat_non_aoi_looks_as_missing = TRUE |
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
center_predictors = function(data, predictors) { | |
if (!require('dplyr')) stop("Dplyr required") | |
require('lazyeval') | |
dots = list() | |
for (i in seq_along(predictors)) { | |
name = paste0(predictors[i], "_C") | |
if (is.factor(data[[predictors[i]]])) { | |
if (length(levels(data[[predictors[i]]])) > 2) stop("'", predictors[i], "' is a factor with more than 2 levels, cannot center.") | |
message("'", predictors[i], "' is a factor, will convert so that '", levels(data[[predictors[i]]])[2], "' will be 'positive'.") |
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
# This takes a folder of session files, converts them to dataframe | |
## MAIN: | |
convert_session_files = function(path, | |
trial_advance_str= "TrialNum", | |
identifier_colnames = c("TrialNum", "BlockNum", "PhaseNum"), | |
participant_string = "subject_code", | |
exp_time_string = "start_time", | |
overwrite_conflict_function = NULL, | |
echo=TRUE) { |
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
# Dplyr's Join w/ Progress Bar | |
# | |
# @author Jacob Dink | |
# jacobwdink@gmail.com | |
# github.com/jwdink | |
# | |
# @created April 8, 2015 | |
# | |
# Dplyr's join functions with a progress bar. Hacky but helpful. | |
# Don't call this function, call the dplyr-named versions (e.g., left_join_pb) |
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
summary_se = function(data, measurevar, idvar, betweenvars) { | |
require('dplyr') | |
require('lazyeval') | |
summarized = data %>% | |
group_by_(.dots=c(idvar, betweenvars)) %>% | |
dplyr::summarise_(.dots = list( | |
MeasureVar = interp( ~mean( MEASUREVAR, na.rm=TRUE), MEASUREVAR = as.name(measurevar) ) | |
)) %>% | |
ungroup() %>% |
NewerOlder