drndr/statcodesearch huggingface dataset:
File: 2.Ginteger_CrossSex_skewers.R

Comment: 6. Extract & plot estimates Is evolution more comparable to B0 or B1?
Category: Visualization
Code:
describe_posterior((r.delta.z[,1,])) # B0_Conc describe_posterior((r.delta.z[,2,])) # B0_Disc describe_posterior((r.delta.z[,3,])) # B1_Conc describe_posterior((r.delta.z[,4,])) # B1_Disc
File: Data_preparation_Sample_C.R

Comment: for each subject, aggregate his/her selfratings across all interactions (in second and third week of eventbased assessment)
Category: Data Variable
Code:
app_SR_aggr <- aggregate(app_SR, by=list(app_SR$id_a), mean)

Comment: recode abitur grades which were not provided but stored as 0, and grades that were provided in units of the wrong grading system
Category: Data Variable
Code:
surv2345$abitur_grade[surv2345$abitur_grade == 0] <- NA surv2345$abitur_grade[surv2345$abitur_grade == 12] <- 2.0 surv2345$abitur_grade[surv2345$abitur_grade == 13] <- 1.7

Comment: define a function which, for each person, selects the first nonNA measurement he provided out of three time points ( out of three variables)
Category: Data Variable
Code:
firstnonNA_3timepoints <- function(df) {if(all(is.na(df))){ NA } else if (!is.na(df[1])){ df[1] } else if (!is.na(df[2])){ df[2] } else if (!is.na(df[3])){ df[3] } }

Comment: for the exam grades 15 to 18 which have been assessed only at the last occasions (Survey 5), save the grade in new variable for consistency in notation
Category: Data Variable
Code:
surv2345$retro_grades_15 <- surv2345$retro_grades_15_t5 surv2345$retro_grades_16 <- surv2345$retro_grades_16_t5 surv2345$retro_grades_17 <- surv2345$retro_grades_17_t5 surv2345$retro_grades_18 <- surv2345$retro_grades_18_t5

Comment: select variables (all 18 exam grades) to be aggregated for mean exam grade
Category: Data Variable
Code:
retro_grades_df <- as.matrix(surv2345[,paste0("retro_grades_",1:18)])

Comment: Select variables for the analyses and save data frame that will be uploaded in the OSF
Category: Data Variable
Code:
connect_osf <- select(connect, Z_Raven_self:Z_MWTB_obj, Z_global_selfeval:Z_achievement) write.table(connect_osf, file="Data_Sample_C_connect.txt",sep = "\t",col.names=TRUE)

Comment: DESCRIPTIVE STATISTICS compute and save sample statistics (age distribution, number of females)
Category: Data Variable
Code:
age <- round(select(psych::describe(connect_descr$age), n, min, max, mean, sd),2) age$n <- nrow(connect_descr) sampstats <- mutate(age, female=plyr::count(connect_descr$sex)[plyr::count(connect_descr$sex)[,1]=="1",]["freq"] ) write.table(sampstats, file="Descriptives/age_sex_Sample_C_connect.dat", sep="\t", row.names=FALSE)

Comment: compute and save correlation table of variables before aggregation and standardization
Category: Data Variable
Code:
cor_raw <- corcons(connect_descr) write.table(cor_raw, file="Descriptives/correlations_raw_Sample_C_connect.dat", sep="\t")
File: BeliefsScale_IRT_Rscript.R

Comment: DIFFERENTIAL ITEM FUNCTIONING Create trichotomous income variable
Category: Data Variable
Code:
data = data %>% mutate( income3 = recode(income, '1=1;; 2=1;; 3=1;; 4=1;; 5=1;; 6=1;; 7=1;; 8=1;; 9=2;; 10=2;; 11=2;; 12=2;; 13=2;; 14=3;; 15=3;; 16=3;; 17=3;; 18=3')) q1merit = data[c("Q1A", "Q1B", "Q1H", "Q1N")] q1opportunity = data[c("Q1C", "Q1D", "Q1F", "Q1G")] q1chance = data[c("Q1I", "Q1O", "Q1P", "Q1Q")] q2merit = data[c("Q2A", "Q2B", "Q2H", "Q2N")] q2opportunity = data[c("Q2C", "Q2D", "Q2F", "Q2G")] q2chance = data[c("Q2I", "Q2O", "Q2Q", "Q2R")] q3merit = data[c("Q3A", "Q3B", "Q3H", "Q3N")] q3opportunity = data[c("Q3C", "Q3D", "Q3F", "Q3G")] q3chance = data[c("Q3I", "Q3O", "Q3P", "Q3Q")] q4merit = data[c("Q4B", "Q4C", "Q4I", "Q4N")] q4opportunity = data[c("Q4D", "Q4E", "Q4G", "Q4H")] q4chance = data[c("Q4J", "Q4O", "Q4P", "Q4Q")] sesmerit = data[c("hs_merit", "ls_merit", "ha_merit", "la_merit")] sesopportunity = data[c("hs_opportunity", "ls_opportunity", "ha_opportunity", "la_opportunity")] seschance = data[c("hs_chance", "ls_chance", "ha_chance", "la_chance")] merit_full = data[c("hs_efft", "hs_abil", "ls_efft", "ls_abil", "ha_efft", "la_efft")] gender = data$gender age = data$AGE4 politic = data$D3 income = data$income3 educ = data$EDUC4
File: exp1 simulated analysis.R

Comment: Display distribution of efficacy judgments (can be used to set a prior on the next experiment)
Category: Visualization
Code:
eff_all <- c(eff_nograph, eff_graph) par(mfrow=c(2,3)) myhist("Efficacy", eff_all, 1, 9, N/2) myhist("Efficacy - no graph", eff_nograph, 1, 9, N/4) myhist("Efficacy - graph", eff_graph, 1, 9, N/4) cat("Grand mean for efficacy: ", format_number(mean(eff_all)), "\n")
File: 7) agr_yearly_model.R

Comment: Models by social network measure 1. Indegree
Category: Data Variable
Code:
m1 <- glmer(pup_year_surv~indegree + valley + overall.index + pup_sex + pup_littersizeborn + mother_age + network_size + pup_emerjdate + overall.index*indegree + valley*indegree + (1|mother_uid) + (1|pup_yrborn), control = glmerControl("bobyqa", optCtrl=list(maxfun=2e5)), data=sur_data, family= binomial) summary(m1)
File: Analysis.R

Comment: remove upper triangle of correlation matrix
Category: Data Variable
Code:
if(removeTriangle[1]=="upper"){ Rnew <- as.matrix(Rnew) Rnew[upper.tri(Rnew, diag = TRUE)] <- "" Rnew <- as.data.frame(Rnew) }

Comment: put SDs in parantheses
Category: Data Variable
Code:
mutate(gender_sd = paste0("(", gender_sd, ")"), age_sd = paste0("(", age_sd, ")"), parent_sd = paste0("(", parent_sd, ")"), pol_sd = paste0("(", pol_sd, ")")) %>% mutate(gender_sd = paste0("(", gender_sd, ")"), age_sd = paste0("(", age_sd, ")"), parent_sd = paste0("(", parent_sd, ")"), pol_sd = paste0("(", pol_sd, ")")) %>% mutate(intent_apply_job_sd = paste0("(", intent_apply_job_sd, ")"), intent_apply_ps_sd = paste0("(", intent_apply_ps_sd, ")"), psm_sd = paste0("(", psm_sd, ")"), pofit_sd = paste0("(", pofit_sd, ")"), pjfit_sd = paste0("(", pjfit_sd, ")")) %>% mutate(intent_apply_job_sd = paste0("(", intent_apply_job_sd, ")"), intent_apply_ps_sd = paste0("(", intent_apply_ps_sd, ")"), psm_sd = paste0("(", psm_sd, ")"), pofit_sd = paste0("(", pofit_sd, ")"), pjfit_sd = paste0("(", pjfit_sd, ")")) %>%

Comment: 5.3 Pirateplot for dependent variables
Category: Visualization
Code:
df_pirate_dv <- tibble(dv = c(df$intent_apply_job, df$intent_apply_ps), group = c(rep.int(0, length(df$intent_apply_job)), rep.int(1, length(df$intent_apply_ps)))) %>% mutate(group = factor(group, labels = c("Intention to\napply for job", "Intention to apply\nfor public service"))) pirate_dvs <- yarrr::pirateplot(dv ~ group, data = df_pirate_dv, inf.method = "ci", xlab = "Dependent variable", ylab = "", theme = 2, cex.lab = 1.2, cex.axis = 1.2, cex.names = 1.2) pirate_dvs <- recordPlot() # contains all plotting information png("./output/Appendix_pirate_dvs.png") pirate_dvs dev.off()
File: load_my_functions.R

Comment: Load the functions for the raincloud plots
Category: Visualization
Code:
source('funcs/R_rainclouds.R')
File: 02_analysis.R

Comment: Save the result and load if you run the permutation test on a different computer than the visualizations
Category: Visualization
Code:
save(list.res,file="results.Rdata") load("results.Rdata")
File: sat_curve.R

Comment: data as a scatter plot, column s for x and column v for y, size 4 points, use the sat_curve data frame as the source
Category: Visualization
Code:
geom_point(data = sat_curve, aes(x = s, y = v), size = 4) +

Comment: fit as a line plot, use the mm_fit data frame as the data source
Category: Visualization
Code:
geom_line(data = mm_fit, aes(x = s, y = v)) +

Comment: change the axis label text to size 22, bold, and black color
Category: Visualization
Code:
axis.text.x = element_text(size = 22, face = "bold", color = "black"), axis.text.y = element_text(size = 22, face = "bold", color = "black")) +
File: analyze_scan_model_hadza.R

Comment: sequence of age inputs within range of model: (15, 75) years old
Category: Data Variable
Code:
seq.length <- length(seq(15, 75, 1))

Comment: Define link function with softmax transformation The following function is taken from Koster and McElreath (2017) Modifications made to accommodate current model structure (e.g. addition of com_id, month)
Category: Statistical Modeling
Code:
link.mn <- function( data ) { K <- dim(post$v_id)[3] + 1 ns <- dim(post$v_id)[1] if ( missing(data) ) stop( "BOOM: Need data argument" ) n <- seq.length softmax2 <- function(x) { x <- max(x) - x exp(-x)/sum(exp(-x)) } p <- list() for ( i in 1:n ) { p[[i]] <- sapply( 1:K , function(k) { if ( k < K ) { ptemp <- post$a[,k] + post$bA[,k] * data$age_z[i] + post$bQ[,k] * data$age_zq[i] + post$bT[,k] * data$time_z[i] + post$bTQ[,k] * data$time_zq[i] if ( data$id[i]>0 ) ptemp <- ptemp + post$v_id[,data$id[i],k] if ( data$com_id[i]>0 ) ptemp <- ptemp + post$v_com[,data$com_id[i],k] if ( data$month_id[i]>0 ) ptemp <- ptemp + post$v_month[,data$month_id[i],k] } else { ptemp <- rep(0,ns) } return(ptemp) })

Comment: The values are converted to probabilities using the softmax function which ensures that the predicted values across categories sum to 100% probabilities.
Category: Statistical Modeling
Code:
for ( s in 1:ns ) p[[i]][s,] <- softmax2( p[[i]][s,] ) } return(p) } for ( s in 1:ns ) p[[i]][s,] <- softmax2( p[[i]][s,] ) } return(p) } low_age <- (15 - mean_age_female)/sd_age_female high_age <- (75 - mean_age_female)/sd_age_female

Comment: everything will be calculated over the "adult" interval from 15 to 75
Category: Data Variable
Code:
age_seq <- (seq(15, 75, 1)- mean_age_female)/sd_age_female

Comment: We create a data frame from age_seq and its second order polynomial, holding most of predictors at their sample mean. In the original Koster+McElreath paper, they specified 8:00 am for the time of day in order to effect a more sensible alignment with the empirical data. In this case, we hold that parameter at 0, which therefore corresponds with the mean time of day in our dataset for behavioral observations (0.532 ~12:45). Also, as we noted earlier in the notes about the multinomial link function, we set "id" to zero in order to average over the random effects.
Category: Statistical Modeling
Code:
pred_dat <- data.frame( id = 0 , age_z = age_seq, age_zq = age_seq^2, time_z = 0, time_zq = 0, com_id = 0, month_id = 0 ) p <- link.mn ( pred_dat )
File: data_preperation_functions.R

Comment: Biodiversity conversion general form is Index (Maxent ^ wM + Abundance ^ wL )^(1/(wM+wL)) but would need to take care of how this scales
Category: Statistical Modeling
Code:
pro.fun <- function(x, abuntab, zonename){ (x^wM*abuntab[,which(names(abuntab)==zonename)]^wL)^(1/(wM+wL))}
File: refugeeservice_varwork2.R

Comment: Construct variable for number of family members in country
Category: Data Variable
Code:
famcountry = data4$partnerwhere + data4$mumwhere + data4$dadwhere table(famcountry) data4$famcountry <- famcountry hist(data4$famcountry) sum(is.na(data4$famcountry)) #175
File: NetworkToolbox.R

Comment: Plot network latent variable on CFA latent variable
Category: Visualization
Code:
layout(t(c(1,2))) plot(cfaLV, netLV, main = "Network Latent Variable\non CFA Latent Variable", ylab = "Network Latent Variable", xlab = "CFA Latent Variable")

Comment: Plot participant means on CFA latent variable
Category: Visualization
Code:
plot(cfaLV, pmeans, main = "Participant Means on\nCFA Latent Variable", ylab = "Participant Means", xlab = "CFA Latent Variable")
File: PWLcapturedByModel.R

Comment: initialize matrices to store validation results
Category: Data Variable
Code:
WklValidation <- matrix(nrow = nrow_max, ncol = 13, dimnames = list(seq(nrow_max), c("distribution", "nProfiles_checked", "day_after_burial", "timewindow_lower", "timewindow_upper", "likelihood_reported", "likelihoodSpread_reported", "distribution_reported", "sensitivity_reported", "size_reported", "sizeSpread_reported", "grain_size_reported", "data_quality"))) WklValidation_char <- matrix(nrow = nrow_max, ncol = 10, dimnames = list(seq(nrow_max), c("vf_uuid", "pwl_uuid", "pwl", "validation_date", "band", "timing_mode", "gtype_class", "gtype_rank", "comment", "danger_rating"))) vf_uuid <- NA
File: 06 - Trends.R

Comment: run linear models on predicted probabilities, to calculate the trend
Category: Statistical Modeling
Code:
models <- pred %>% group_by(x, country) %>% nest() %>% mutate(models = map(data, ~ lm(predicted ~ wave, data = .))) %>% spread_coef(models, se = TRUE)
File: Data_preparation_Sample_D.r

Comment: one participant has a typing error in the age variable (stated he was 2). Set to NA.
Category: Data Variable
Code:
mst1[which(mst1$age == 2), "age"] <- NA
File: basic_mods.R

Comment: association between vote and ideology
Category: Data Variable
Code:
ggplot(dat, aes(x = Ideology, y = Percent.Vote.Rep)) + geom_vline(xintercept = .50, color = "gray50", linetype = 2) + geom_hline(yintercept = .50, color = "gray50", linetype = 2) + stat_poly_line() + stat_correlation(label.x = "left", small.r = TRUE) + geom_point() + geom_text_repel(size = 3, aes(label = Group)) + labs(y = "Proportion Voting Republican", x = "Ideology") + coord_cartesian(xlim = c(0, 1), ylim = c(0, 1)) + theme_cowplot() ggsave("figures/predictor_scatter.pdf", width = 5.5, height = 5)
File: 2_idDiffs.R

Comment: Make a dot and a line color column depending on the significance level Check significance level and if significant add respective color to new column
Category: Visualization
Code:
ageR = data.frame(dotCol = rep(ifelse(summary(lm(initLevel ~ age, data = id_df))$coefficients[2,4]< 0.05, "khaki3", "lightgrey"), length(unique(id_df$userCode))), lineCol = rep(ifelse(summary(lm(initLevel ~ age, data = id_df))$coefficients[2,4]< 0.05, "cyan4", "darkgrey"), length(unique(id_df$userCode)))) educR = data.frame(dotCol = rep(ifelse(summary(lm(initLevel ~ educ_y, data = id_df))$coefficients[2,4]< 0.05, "khaki3", "lightgrey"), length(unique(id_df$userCode))), lineCol = rep(ifelse(summary(lm(initLevel ~ educ_y, data = id_df))$coefficients[2,4]< 0.05, "cyan4", "darkgrey"), length(unique(id_df$userCode)))) blpR = data.frame(dotCol = rep(ifelse(summary(lm(initLevel ~ BLP, data = id_df))$coefficients[2,4]< 0.05, "khaki3", "lightgrey"), length(unique(id_df$userCode))), lineCol = rep(ifelse(summary(lm(initLevel ~ BLP, data = id_df))$coefficients[2,4]< 0.05, "cyan4", "darkgrey"), length(unique(id_df$userCode)))) actR = data.frame(dotCol = rep(ifelse(summary(lm(initLevel ~ Act_total, data = id_df))$coefficients[2,4]< 0.05, "khaki3", "lightgrey"), length(unique(id_df$userCode))), lineCol = rep(ifelse(summary(lm(initLevel ~ Act_total, data = id_df))$coefficients[2,4]< 0.05, "cyan4", "darkgrey"), length(unique(id_df$userCode)))) motivR = data.frame(dotCol = rep(ifelse(summary(lm(initLevel ~ socioAffect_init, data = id_df))$coefficients[2,4]< 0.05, "khaki3", "lightgrey"), length(unique(id_df$userCode))), lineCol = rep(ifelse(summary(lm(initLevel ~ socioAffect_init, data = id_df))$coefficients[2,4]< 0.05, "cyan4", "darkgrey"), length(unique(id_df$userCode)))) tmp = rbind.data.frame(ageR, educR, blpR, actR, motivR) corrDF = cbind(corrDF, tmp)
File: demo_script_2018_10_02.R

Comment: Sample from those names 200 times, with replacement
Category: Statistical Modeling
Code:
animal <- sample(categories, 200, replace = TRUE)

Comment: Create random variables Use rnorm() with varying means and SDs
Category: Data Variable
Code:
length <- rnorm(200, 30, 8) weight <- rnorm(200, 4, 2) happiness <- rnorm(200, 3.5, 1)

Comment: Examine descriptive statistics Use the pipe, group_by(), and summarise() to get means, SDs, and medians for each category
Category: Data Variable
Code:
animal_data %>% group_by(animal) %>% summarise( weight_mean = mean(weight), weight_sd = sd(weight), weight_median = median(weight) )

Comment: Subset data to include only the first two categories Use filter() to select only rows that pass the given logical test
Category: Data Variable
Code:
subset_1 <- animal_data %>% filter(animal == "puppy" | animal == "kitten")

Comment: Use subset for ttest Welch's ttest
Category: Statistical Test
Code:
t.test(weight ~ animal, data = subset_1)
File: behavior_analyses.R

Comment: plot spaghettiplot for minute 1 and minute 5
Category: Visualization
Code:
df_1_5 <- rbind(df_min1, df_min5) df_1_5 <- df_1_5 %>% mutate(range=droplevels(range)) p <- ggplot(data = df_1_5, aes(x = range, y = count, group = pp)) p + geom_point() p + geom_line() p + geom_line() + facet_grid(. ~ condition) p <- ggplot(data = df_min, aes(x = range, y = count, group = pp)) p + geom_point() p + geom_line() p + geom_line() + facet_grid(. ~ condition)

Comment: do 3 way anova including the factor in which condition they are in
Category: Statistical Test
Code:
bfFull = anovaBF(count ~ condition + range + experiment + condition:range:experiment, data = df_b) bfFull[4]/bfFull[3] bfFull[18]/bfFull[17] bf1 = anovaBF(count ~ condition + range + experiment, data = df_b)
File: Analysis.R

Comment: pc: critical pvalue Overview: Creates a vector of the same length as the number of tests submitted to pcurve, significant and not, and computes the proportion of pvalues expected to be smaller than {pc} given the d.f. and outputs the entire vector, with NA values where needed Ftests (& thus ttests)
Category: Statistical Test
Code:
prop=ifelse(family=="f" & p<.05,1-pf(qf(1-pc,df1=df1, df2=df2),df1=df1, df2=df2, ncp=ncp33),NA)

Comment: Create vector that numbers studies 1 to N,includes n.s. studies
Category: Data Variable
Code:
k=seq(from=1,to=length(raw))

Comment: 1.2 Parse the entered text into usable statistical results 1.3 Create test type indicator
Category: Statistical Test
Code:
stat=substring(raw,1,1) #stat: t,f,z,c,r test=ifelse(stat=="r","t",stat) #test: t,f,z,c (r-->t)

Comment: Make red dot at the estimate
Category: Visualization
Code:
points(hat,min(fit,na.rm=TRUE),pch=19,col="red",cex=2)

Comment: This loop creates a vector, blue, with 5 elements, with the proportions of p.01,p.02...p.05
Category: Data Variable
Code:
for (i in c(.01,.02,.03,.04,.05)) blue=c(blue,sum(ps==i,na.rm=TRUE)/ksig*100)
File: SRIS,FullScaleIRTModelsandPlots.R

Comment: FIG 3: scree plot for parallel analysis
Category: Visualization
Code:
rscree<-as.data.frame(cbind(spar$fa.values, spar$fa.simr)) colnames(rscree)<-c("Actual","Resampled") rscree$item<-seq.int(1, 12, 1) refplot<-pivot_longer(rscree, cols=1:2, names_to="Method") refplot2<-refplot %>% filter(item<5) iscree<-as.data.frame(cbind(ipar$fa.values, ipar$fa.simr)) colnames(iscree)<-c("Actual","Resampled") iscree$item<-seq.int(1, 8, 1) insplot<-pivot_longer(iscree, cols=1:2, names_to="Method") insplot2<-insplot %>% filter(item<5) refeig<-ggline(refplot2, x="item", y="value", group = "Method", color="Method", size=1.1, palette = paletteer_d("palettetown::tangela", direction=-1), xlab="Factor", ylab="Eigenvalue", title="Self-reflection")+ theme_minimal_hgrid(font_size=12, font_family = "Fira Sans Medium") scree.a<-ggpar(refeig, ylim = c(0,6), yticks.by=1, legend = c(.7,.77), legend.title = "") scree.a inseig<-ggline(insplot2, x="item", y="value", group = "Method", color="Method", size=1.1, palette = paletteer_d("palettetown::tangela", direction=-1), xlab="Factor", ylab="", title="Insight")+ theme_minimal_hgrid(font_size=12, font_family = "Fira Sans Medium") scree.b<-ggpar(inseig, ylim = c(0, 6), yticks.by=1, legend = c(.7,.77), legend.title = "") scree.b
File: Malawi_interpolation.R

Comment: make sure data are in chronological order
Category: Data Variable
Code:
pollenData <- pollenData[order(pollenData$age),] lakeData <- lakeData[order(lakeData$age),] charcoalData <- charcoalData[order(charcoalData$age),] tail(pollenData) tail(lakeData) tail(charcoalData)
File: Getting Started With R - Script Key.R

Comment: examine descriptives of newly created variables here we are combining the dplyr and summarytools packages to subset the data and then get descriptives
Category: Data Variable
Code:
eid_dat %>% dplyr::select(swl_mean, meim_ex_mean, meim_co_mean) %>% summarytools::descr()

Comment: step 6: multiple regression with exploration and commitment predicting SWL this function is in base R so no package to call
Category: Statistical Modeling
Code:
regression <- lm(swl_mean ~ meim_ex_mean + meim_co_mean, data=eid_dat) summary(regression) confint(regression)

Comment: step 7: create scattterplots using ggplot2 scatterplot of exploration with SWL there are many more options you can play with for customization. I just included some basics here
Category: Visualization
Code:
ex_swl_scatter <- ggplot2::ggplot(eid_dat, aes(meim_ex_mean, swl_mean)) + geom_point() + ggtitle("My Scatterplot") + xlab("Ethnic Identity Exploration (mean)") + ylab("Satisfaction with Life (mean)") + geom_smooth(method="lm") ex_swl_scatter

Comment: scatterplot of commitment with SWL
Category: Visualization
Code:
co_swl_scatter <- ggplot2::ggplot(eid_dat, aes(meim_co_mean, swl_mean)) + geom_point() + ggtitle("My Scatterplot") + xlab("Ethnic Identity Commitment (mean)") + ylab("Satisfaction with Life (mean)") + geom_smooth(method="lm") co_swl_scatter

Comment: step 8: indepedent samples ttests also in base R. note that Welch's ttest is the default this set is testing for mean differences by whether they were born in the U.S.
Category: Statistical Test
Code:
t.test(eid_dat$meim_ex_mean ~ eid_dat$usborn) t.test(eid_dat$meim_co_mean ~ eid_dat$usborn) t.test(eid_dat$swl_mean ~ eid_dat$usborn)

Comment: step 11: create a series of boxplots to go with the previous ANOVAs note that the code here is only slightly different from the one variable case you can/should add elements to format the plots, as you did previously
Category: Visualization
Code:
borngen_ex_boxplot <- ggplot2::ggplot(eid_dat, aes(usborn, meim_ex_mean, fill=firstgen)) + geom_boxplot(alpha = 0.5) borngen_ex_boxplot borngen_co_boxplot <- ggplot2::ggplot(eid_dat, aes(usborn, meim_co_mean, fill=firstgen)) + geom_boxplot(alpha = 0.5) borngen_co_boxplot borngen_swl_boxplot <- ggplot2::ggplot(eid_dat, aes(usborn, swl_mean, fill=firstgen)) + geom_boxplot(alpha = 0.5) borngen_swl_boxplot
File: Power_Analysis_OSF_22.R

Comment: Add a plotting function to get power curve
Category: Visualization
Code:
plot_power_extend <- function(object, target = .80, ...) { nsim <- object[[1]]$n df <- purrr::map_dfr(object, powerinterval, .id = "n", ...) df$n <- as.integer(df$n) ggplot(df, aes(x = n, y = mean, group = 1)) + geom_hline(yintercept = target) + geom_smooth(method = "glm", formula = cbind(y * nsim, (1 - y) * nsim) ~ x, method.args = list(family = binomial("probit"))) + geom_pointrange(aes(ymin = lower, ymax = upper)) + labs(y = "power") + ylim(0, 1) }
File: exp02_prep.R

Comment: check duplicate trials per participant (post)
Category: Data Variable
Code:
xtabs(~subj+trial,data=rawdat.all) table(rawdat.all$subj)
File: 4_Compute_beta_diversity_metrics.R

Comment: remove duplicate species per file, and species level data
Category: Data Variable
Code:
data2.5 <- data2[!data2$species == 'Certhia_sp.',] data2.6 <- data2.5[!data2.5$species == 'Regulus_sp.',] data3 <- data2.6 %>% group_by(Plot_no) %>% mutate(whichday = as.integer(factor(date))) data4 <- data3 %>% group_by(Plot_no, filename) %>% mutate(seq=cur_group_id())
File: 0_Data-Prep.R

Comment: Show sample sizes per country
Category: Visualization
Code:
pa12_resp_s %>% group_by(CNT) %>% summarise(n = n())
File: Figures for paper.R

Comment: Gaze Duration Descriptive stats per ID
Category: Data Variable
Code:
BFSGDesc <- BirdFSG %>% group_by(ID, Stimuli) %>% summarise (MGaze = mean(Gaze), sd=sd(Gaze), n=n(), se = sd/sqrt(n)) ;; BFSGDesc$Stimuli <- paste( BFSGDesc$Stimuli, "S", sep="") BFSGDesc BNADDesc <- BirdNAD %>% group_by(ID, Stimuli) %>% summarise (MGaze = mean(Gaze), sd=sd(Gaze), n=n(), se = sd/sqrt(n)) ;; BNADDesc$Stimuli <- paste( BNADDesc$Stimuli, "S", sep="") BFSGDesc <- as.data.frame(BFSGDesc);; BNADDesc <- as.data.frame(BNADDesc);; BFSGDesc$Stimuli <- as.factor(as.character(BFSGDesc$Stimuli)) BNADDesc$Stimuli <- as.factor(as.character(BNADDesc$Stimuli)) BFSGDesc