drndr/statcodesearch huggingface dataset:
File: functions_2.R

Comment: Graph of the distribution of pvalues for each effect
Category: Visualization
Code:
pvalue.plot <- ggplot(melt_pvalue,aes(x = value)) + facet_wrap(~variable, ncol = 5) + geom_histogram()

Comment: Graph of the distribution of standard estimates for each effect
Category: Visualization
Code:
est.std.plot <- ggplot(melt_est.std,aes(x = value)) + facet_wrap(~variable, ncol = 5) + geom_histogram() list.result <- list("dist_pvalue.plot" = pvalue.plot, "dist_est.std.plot" = est.std.plot) return(list.result)

Comment: returns plot of pvalue disttribution, plot of standard estimates distribution 
Category: Visualization
Code:
list.result <- list("dist_pvalue.plot" = pvalue.plot, "dist_est.std.plot" = est.std.plot) return(list.result)

Comment:   Model estimates plot   Arguments: standard estimates distribution, pvalues distributions, use sign level TREU/FALSE, level of signicance, plot title 
Category: Visualization
Code:
create.model_estimates.plot <- function (est.std_dist, pvalue_dist, significant = FALSE, sig_level=.05, title = NULL){

Comment: Median of each standard estimates and TRUE/FALSE values if mean(pvalues) < sig_level
Category: Statistical Test
Code:
est.std_All <- data.frame(cbind(colMeans(est.std_dist), colMeans(pvalue_dist) <= sig_level))
File: R_Code_Hui_et_al.R

Comment:  Change the participantID to a shorter & uniform name "Subject" 
Category: Data Variable
Code:
names(d)[names(d) == "Participant.Public.ID"] <- "Subject"

Comment:  For trimmed set, we remove any RT that is too long (>2500ms) 
Category: Data Variable
Code:
d_trimmed = d %>% filter (acc == 2, Reaction.Time > 300, Reaction.Time < 2500)

Comment: Plotting   create a dataset that contains means of both oddnumbered & evennumbered items' RTs
Category: Visualization
Code:
raw_untrimmed<-inner_join(x= mean.o, y=mean.e, by="Subject") names(raw_untrimmed) <- c("Subject", "Odd", "Even")

Comment: AVERAGE BY PARTICIPANT
Category: Data Variable
Code:
mean.e = de %>% group_by(Subject) %>% summarise(mean(rt.diff)) mean.o = do %>% group_by(Subject) %>% summarise(mean(rt.diff)) mean.e = de %>% group_by(Subject) %>% summarise(mean(zrt.diff)) mean.o = do %>% group_by(Subject) %>% summarise(mean(zrt.diff)) mean.e = de %>% group_by(Subject) %>% summarise(mean(zrt.diff)) mean.o = do %>% group_by(Subject) %>% summarise(mean(zrt.diff))

Comment: combine them into one data frame
Category: Data Variable
Code:
person <- inner_join(person_rand_e, person_rand_o, by = "Subject", suffix = c("_even", "_odd"))
File: SI_4_Statistical_analyses.R

Comment: Wilcoxon ranksum test on widths of unbroken artefacts:
Category: Statistical Test
Code:
results <- wilcox.test(An2entire$Width,Gmeentire$Width) Z       <- qnorm(results$p.value)

Comment: Wilcoxon ranksum test on lengths of unbroken artefacts:
Category: Statistical Test
Code:
results <- wilcox.test(An2entire$Length,Gmeentire$Length) Z       <- qnorm(results$p.value)
File: af_homing_dataproc.R

Comment: DATA DOWNSAMPLING  add collumns with delta distance and delta time for downsampling
Category: Data Variable
Code:
trajectory.df <- trajectory.df %>% group_by(id) %>% mutate(time_diff = difftime(dt, lag(dt, n = 1L), units = "min"), delta_x = x_utm - lag(x_utm, n = 1L), delta_y = y_utm - lag(y_utm, n = 1L), dist = sqrt(delta_x^2+delta_y^2))

Comment: Caculate daily cumulative distances and time lags Calculate speed Join with relocation info Add consecutive number per individual to indicate tracking day
Category: Data Variable
Code:
daily <- trajectory.df %>% group_by(id, date) %>% filter(!dist == "NA") %>% dplyr::summarize(daily_dist = sum(dist), sex = first(sex), time_lag_min = sum(time_lag_min)) %>% mutate(id_day = paste(id, date), daily_speed = (daily_dist/as.numeric(time_lag_min) * 60)) %>% left_join(relocs.perday) %>% group_by(id) %>% mutate(trans_day = row_number())

Comment: Split up the trajectories into 50m and 200m translocations
Category: Data Variable
Code:
trajectory50m <- trajectory.df %>% filter(trans_group == "50m") trajectory200m <- trajectory.df %>% filter(trans_group == "200m")

Comment: Plot daily movement by daily temp & sex
Category: Visualization
Code:
ggplot(data = daily, aes(x = temp, y = daily_dist, group = sex, color = sex)) + geom_point() + stat_smooth(method=lm) + theme_bw()

Comment: Plot daily movement by daytime rainfall & sex
Category: Visualization
Code:
ggplot(data = daily, aes(x = rain_daytime, y = daily_dist, group = sex, color = sex)) + geom_point() + stat_smooth(method=lm) + theme_bw()

Comment: Plot daily movement by cumulative rainfall & sex
Category: Visualization
Code:
ggplot(data = daily, aes(x = rain_cumul, y = daily_dist, group = sex, color = sex)) + geom_point() + stat_smooth(method=lm) + theme_bw()
File: funs.R

Comment:  x is a matrix containing the data  method : correlation method. "pearson"" or "spearman"" is supported  removeTriangle : remove upper or lower triangle  results :  if "html" or "latex"  the results will be displayed in html or latex format 
Category: Statistical Test
Code:
corstars <-function(x, method=c("pearson", "spearman"), removeTriangle=c("upper", "lower"), result=c("none", "html", "latex")){
File: sim_data_LissonEtAl2020.R

Comment: Diagonal matrix Tau used to scale the z_w
Category: Data Variable
Code:
Tau_w <- matrix(c(DA.mp$`tau_w[1]`,0,0, 0,DA.mp$`tau_w[2]`,0, 0,0,DA.mp$`tau_w[3]` ),nrow=3,ncol=3)
File: 20180806funnelplotlifesatisfaction.R

Comment: Run fixed effect model
Category: Statistical Modeling
Code:
life <- rma(yi = corrs$cor, vi = corrs$vi, measure = "COR", method = "FE")
File: p_curve_d_distribution_power_app_Lakens.R

Comment: Set max Y for graph
Category: Visualization
Code:
y_max<-max(d_dist)+1
File: summarySE.R

Comment:  This does the summary. For each group's data frame, return a vector with  N, mean, median, and sd 
Category: Data Variable
Code:
datac <- ddply(data, groupvars, .drop=.drop, .fun = function(xx, col) { c(N    = length2(xx[[col]], na.rm=na.rm), mean = mean   (xx[[col]], na.rm=na.rm), median = median (xx[[col]], na.rm=na.rm), sd   = sd     (xx[[col]], na.rm=na.rm) ) }, measurevar )

Comment:  Rename the "mean" and "median" columns 
Category: Data Variable
Code:
datac <- rename(datac, c("mean" = paste(measurevar, "_mean", sep = ""))) datac <- rename(datac, c("median" = paste(measurevar, "_median", sep = ""))) datac$se <- datac$sd / sqrt(datac$N)  # Calculate standard error of the mean
File: batchUploadImages.R

Comment:  A function that reads in one line in the csv file, add tags and texts around it, and write the output line into an output file 
Category: Data Variable
Code:
add_tags <- function(l,o){ image_no <- strsplit(as.character(l[1]),"\\.")[[1]][1] image_URL <- paste("<img src='", as.character(l[2]),"'>",sep="") write(paste("[[Block:", image_no, "]] \n [[Question:DB]] \n [[ID:", image_no, "-image]] \n", image_URL, " \n [[Question:TE:SingleLine]] \n [[ID:", image_no, "-TE]] \n", TE, " \n [[Question:MC:SingleAnswer:Vertical]] \n [[ID:", image_no, "-MC]] \n", MC, " \n [[Choices]] \n", choices_formatted, "\n [[Question:Matrix]] \n [[ID:", image_no, "-ratings]] \n ",rating_prompt," \n [[AdvancedChoices]] \n ", rating_statements_formatted, "\n [[AdvancedAnswers]] \n [[Answer]] \n","1 - Strongly Disagree", "\n [[Answer]] \n 2 \n [[Answer]] \n 3 \n [[Answer]] \n 4 \n [[Answer]] \n 5 \n [[Answer]] \n 6 \n [[Answer]] \n", "7 - Strongly Agree"," \n [[PageBreak]] \n", sep = ""), o, append = TRUE) }
File: save_get_pp_check.R

Comment: Generate a plot for posterior predictive check (evaluate whether the ' posterior predictive data look more or less similar to the observed data) ' ' @param df dataframe with the data ' @param mod Bayesian model ' ' @return plot with posterior predictive check
Category: Visualization
Code:
get_pp_check <- function(df, mod) { map(list(df), ~brms::pp_check(mod,
File: 1_sim_functions.R

Comment:  Simulate a single between group study given sample size n, true (fixed) effect size delta, and heterogeneity (random effect) tau.  Generate data for the experimental group (y_e) and for the control group (y_c). 
Category: Statistical Modeling
Code:
y_e = rnorm(n, 0, 1) + delta + rnorm(1, 0, tau) y_c = rnorm(n, 0, 1)

Comment:  calculate pooled variance S, standardized mean difference d, the variance of d, the pvalue, and N. 
Category: Data Variable
Code:
S = sqrt(((n - 1) * v_e + (n - 1) * v_c) / df) d = (m_e - m_c) / S var.d = (n + n)/(n * n) + (d^2 / (2 * (n + n))) se.d = sqrt(var.d) N = n + n
File: code.R

Comment: Box and Whisker Plots to Compare Models
Category: Visualization
Code:
scales <- list(x=list(relation="free"), y=list(relation="free")) bwplot(results, scales=scales)
File: Sim_Function.R

Comment: stimuli  specify correlations for rnorm_multi (one of several methods)
Category: Data Variable
Code:
stim_cors = stim_i_cor stim = rnorm_multi( n = stim_n, vars = 2, r = stim_cors, mu = 0, # means of random intercepts and slopes are always 0 sd = c(stim_sd, stim_version_sd), varnames = c("stim_i", "stim_version_slope") ) %>% mutate( stim_id = 1:stim_n ) stim_cors = stim_i_cor stim = rnorm_multi( n = stim_n, vars = 2, r = stim_cors, mu = 0, # means of random intercepts and slopes are always 0 sd = c(stim_sd, stim_version_sd), varnames = c("stim_i", "stim_version_slope") ) %>% mutate( stim_id = 1:stim_n ) stim_cors = stim_i_cor stim = rnorm_multi( n = stim_n, vars = 2, r = stim_cors, mu = 0, # means of random intercepts and slopes are always 0 sd = c(stim_sd, stim_version_sd), varnames = c("stim_i", "stim_version_slope") ) %>% mutate( stim_id = 1:stim_n )

Comment: calculate trialspecific effects by adding overall effects and slopes
Category: Statistical Modeling
Code:
version_eff = stim_version_eff + stim_version_slope + sub_version_slope, version_eff = stim_version_eff + stim_version_slope + sub_version_slope, version_eff = stim_version_eff + stim_version_slope + sub_version_slope,
File: CSEP_DataScienceExPhys_Akerman2021.R

Comment:  Take the list of csv files from above, and read them all into R (purrr::map function)  This will download 100 csv files into a list  The reduce function will then bind them all together into a dataframe 
Category: Data Variable
Code:
large_df <- csv_files %>% purrr::map(function(x) { read.csv(x) }) %>% purrr::reduce(cbind)

Comment:  Re structure this dataframe to turn it to long format (pivot_longer)  Keep the X columns in, these are the rowvalues we can use to denote a sample  The column names contain the participant (P) and the session number (S)  It will display with each 1st sample of each session for a given participant, so need to reorder to get sorted by participant, session, then second sample  The names_pattern uses regular expresisons to denote that the names will come from the specified area  i.e., after the P, which could contain any values which occur before the underscore, and likewise after the S 
Category: Data Variable
Code:
large_df <- large_df %>% tidyr::pivot_longer(cols = !contains("X"), names_to = c("participant", "session"), names_pattern = c("P(.*)_S(.*)"), values_to = "heart_rate")  %>% dplyr::rename(seconds = "X") %>% dplyr::arrange(participant, session, seconds) %>% dplyr::mutate(participant = as.factor(participant), session = as.factor(session))
File: 9Graphingspeciesism_Spanish.R

Comment: pool "exp_buc" columns into one column, so that advocacy type is one variable and create new "experienced" column for each level of advocacy type 
Category: Data Variable
Code:
data <- data %>% pivot_longer(names_to = "advocacytype", values_to = "experienced", graphic_exp_buc:disprotest_exp_buc)
File: norms_code.R

Comment: Create variables for residue that is 'present' vs 'absent' This is used for the tables/descriptives AND for color/filling the figures
Category: Data Variable
Code:
data <- dplyr::mutate(data, oro_zero = if_else(valleculae_severity_rating == 0, "Absent", "Present")) data <- dplyr::mutate(data, hypo_zero = if_else(piriform_sinus_severity_rating == 0,"Absent", "Present")) data <- dplyr::mutate(data, epi_zero = if_else(epiglottis_severity_rating == 0, "Absent", "Present")) data <- dplyr::mutate(data, lv_zero = if_else(laryngeal_vestibule_severity_rating == 0, "Absent", "Present")) data <- dplyr::mutate(data, vf_zero = if_else(vocal_folds_severity_rating == 0, "Absent", "Present")) data <- dplyr::mutate(data, sg_zero = if_else(subglottis_severity_rating == 0, "Absent", "Present")) data <- dplyr::mutate(data, pas_zero = if_else(pas_max < 2, "Absent", "Present"))
File: Factor analysis.R

Comment: Diagnostic tests to determine appropriate number of factors in EFA  parallel analysis (includes scree plot) and Very Simple Structure test  optimal number of factors is 6
Category: Statistical Test
Code:
fa.parallel(mainData[, c(2:56)], fm = 'ml', fa = 'fa') vss(mainData[, c(2:56)], n = 8, rotate = 'oblimin', fm = 'mle')
File: 03_Supplement.R

Comment: replace missings values (9 and 99) with NA
Category: Data Variable
Code:
pilot<- na_if(pilot,99) pilot<- na_if(pilot,-9)

Comment: subset of participants with less then 4 missings
Category: Data Variable
Code:
pilot<- subset(pilot, pilot$missings_a < 4) pilot_c <- pilot[,c("SJT_kb_00007","SJT_kb_00028","SJT_kb_00058", "SJT_kb_00054","SJT_kb_00072","SJT_kb_00026", "SJT_kb_00060","SJT_kb_00053","SJT_kb_00039", "SJT_kb_00027","SJT_kb_00015","SJT_kb_00038", "SJT_kb_00035","SJT_kb_00055","SJT_kb_00010")] pilot$missings_c <- apply(pilot_w,1,function(x) sum(is.na(x))) pilot<- subset(pilot, pilot$missings_c < 4) pilot_es <- pilot[,c("SJT_kb_00103","SJT_kb_00197","SJT_kb_00136", "SJT_kb_00134","SJT_kb_00113","SJT_kb_00128", "SJT_kb_00117","SJT_kb_00127","SJT_kb_00104", "SJT_kb_00108","SJT_kb_00094","SJT_kb_00143", "SJT_kb_00116","SJT_kb_00202","SJT_kb_00175")] pilot$missings_es <- apply(pilot_es,1,function(x) sum(is.na(x))) pilot<- subset(pilot, pilot$missings_es < 4)
File: 3VariableCreation.R

Comment: Coding past experiences into binary variables
Category: Data Variable
Code:
data <- data %>% mutate_at(vars("graphic_exp":"attentioncheck_exp"), list(buc = bucketing_experienced)) %>% glimpse

Comment: Coding behaviors into binary variables 0  unselected, 1  selected 
Category: Data Variable
Code:
data <- data %>% mutate_at(vars("behavior_donation":"behavior_none"), list(bin = binary.behavior)) %>% glimpse

Comment: Creating a combined race/ethnicity variable
Category: Data Variable
Code:
data <- data %>% mutate(race.eth = case_when(hispanic == "Yes" ~ "Hispanic or Latinx", race == "Caucasian/White" & hispanic == "No" ~ "White, Non-Latinx", race == "Black or African-American" & hispanic == "No" ~ "Black, Non-Latinx", race == "Asian" & hispanic == "No" ~ "Asian", race == "Multi-Racial" & hispanic == "No" ~ "Multi-Racial", TRUE ~ "Other Races/Ethnicities"))
File: Flux_MainDataAnalyses.R

Comment: correlations between csd_mean and averaged csds for Big Five traits (not mentioned   in the text):
Category: Data Variable
Code:
psych::corr.test( df2$e_csd,df2$csd_mean_e ) psych::corr.test( df2$a_csd,df2$csd_mean_a ) psych::corr.test( df2$pa_csd,df2$csd_mean_pa ) psych::corr.test( df2$na_csd,df2$csd_mean_na )
File: Data_Prep_S1S2.R

Comment:  Participants could select all response options that applied to them in any given situation. Here, we create one dummy variable for every response option. 
Category: Data Variable
Code:
for (i in 1:length(survey$interacting_by)) { v <- unlist(strsplit(survey$interacting_by[i], ",")) if (is.element("1", v)) { survey$TiP[i] <- 1 } if (is.element("2", v)) { survey$ToP[i] <- 1 } if (is.element("3", v)) { survey$TM[i] <- 1 } if (is.element("4", v)) { survey$ChattingWHATSAPP[i] <- 1 } if (is.element("5", v)) { survey$ChattingDATING[i] <- 1 } if (is.element("6", v)) { survey$Emailing[i] <- 1 } if (is.element("7", v)) { survey$Videochatting[i] <- 1 } if (is.element("8", v)) { survey$Facebook[i] <- 1 } if (is.element("9", v)) { survey$Instagram[i] <- 1 } if (is.element("10", v)) { survey$Snapchat[i] <- 1 } if (is.element("11", v)) { survey$Twitter[i] <- 1 } if (is.element("12", v)) { survey$OTHER[i] <- 1 } if (is.element("0", v)) { survey$NoInteraction[i] <- 1 } if (is.element("999", v)) { survey$SKIP[i] <- 1 } } for (i in 1:length(survey$interacting_people)){ v <- unlist(strsplit(survey$interacting_people[i], ",")) if (is.element("1", v)) { survey$Classmates[i] <- 1 } if (is.element("2", v)) { survey$Coworkers[i] <- 1 } if (is.element("3", v)) { survey$Family[i] <- 1 } if (is.element("4", v)) { survey$Friends[i] <- 1 } if (is.element("5", v)) { survey$Roommates[i] <- 1 } if (is.element("6", v)) { survey$Significant_other[i] <- 1 } if (is.element("7", v)) { survey$Strangers[i] <- 1 } if (is.element("8", v)) { survey$OTHER2[i] <- 1 } if (is.element("999", v)) { survey$SKIP2[i] <- 1 } }
File: 4. Compare pre-post.R

Comment: Rescore so high values are what we expect to be positive predictors (e.g. female 2 male 1)
Category: Data Variable
Code:
df$Nationality2 <- df$Nationality df$Nationality2 <- as.integer(df$Nationality2 %in% "Dutch") df$Nationality2[df$Nationality2==0] <- 2 df$Nationality2[df$Nationality2==1] <- 0 df$Nationality2[df$Nationality2==2] <- 1  # Dutch=0 (36), Rest=1 (44) count(df$Nationality2) df$RelationshipStatus2 <- df$RelationshipStatus df$RelationshipStatus2 <- recode(df$RelationshipStatus2, "3" = 2) df$RelationshipStatus2[df$RelationshipStatus2==2] <- 0  # Partnered=0 (30), Single=1 (50) count(df$RelationshipStatus2) df$Gender2 <- df$Gender          # df$Gender2[df$Gender2==3] <- NA  # code 1 nonbinary participant as NA for this to avoid 3 levels df$Gender2[df$Gender2==1] <- 0 df$Gender2[df$Gender2==2] <- 1   # men=0 (19), women=1 (60), 1 NA count(df$Gender2) df$WorkStatus2 <- df$WorkStatus df$WorkStatus2[df$WorkStatus2==2] <- 0 # 54no, 26yes count(df$WorkStatus2) df$MentalHealth2 <- as.numeric(df$MentalHealth) df$MentalHealth2[df$MentalHealth2==1] <- 0 df$MentalHealth2[df$MentalHealth2==2] <- 1   # healthy=0 (59), history=1 (17), 4 NA count(df$MentalHealth2) df$selfefficacy_pre2 <- df$selfefficacy_pre*-1 # reverse code
File: Exp4_buddhist_post.R

Comment: Rating Means and Standard Deviations of Conditions   Unspecified Rating
Category: Statistical Test
Code:
round(mean(unspecified$rating), 2) round(sd(unspecified$rating), 2)
File: ExploratoryAnalyses.R

Comment: Save and export image as .eps (8.18 x 4.88 inch)
Category: Visualization
Code:
if(saveFigures) cairo_ps(file = '../R_Output/Images/AccuracyPerProject_Revision.eps', onefile = TRUE, fallback_resolution = 600, width = 8.18, height = 4.88) par(cex.main = 2.2, mar = c(5, 5.5, 2, 2) + 0.1, mgp = c(3, 1, 0), cex.lab = 2, font.lab = 1, cex.axis = 1.6, bty = 'n', las = 1) plot(x = c(.5, .8), y = c(0, 50), type = 'n', xlab = expression(paste("Accuracy Rate ", omega, " (in %)")), ylab = 'Density', main = '', axes = FALSE) axis(2, lwd.tick = 0, labels = FALSE) axis(1, at = seq(.5, .8, by = .05), labels = seq(50, 80, by = 5)) d <- lapply(split(df$omega, df$condition), density) Map(function(dens, col) polygon(dens, col = col), dens = d, col = figureColors[['cols.transparent']]) text(.64,44.5,'Laypeople\n(Evidence)', cex = 1.3) text(.55,44.5,'Laypeople\n(Description)', cex = 1.3) text(.621,25,'Experts\nML2',  cex = 1.3) text(.75,25, 'Experts\nSSRP', cex = 1.3) graphics.off()

Comment: function to calculate AUC
Category: Statistical Modeling
Code:
groupAUC.description <- pnorm(description.mud / sqrt(2)) # signal distribution has sigma = 1 quantile(groupAUC.description, c(0.025, 0.5, 0.975)) groupAUC.evidence <- pnorm(evidence.mud / sqrt(2)) # signal distribution has sigma = 1 quantile(groupAUC.evidence, c(0.025, 0.5, 0.975))

Comment: get relevant information  compute mode of signal distribution
Category: Statistical Modeling
Code:
estimate_mode <- function(x) { d <- density(x) d$x[which.max(d$y)] } modeD           <- estimate_mode(mud) medianC         <- median(muc) empiricalLambda <- (0.5*modeD) + medianC

Comment: compute CIs for each value of lambda
Category: Statistical Test
Code:
probD      <- quantile(mud, probs = probs) for (i in seq_len(nPoints)){ c        <- lambdas[i] - (0.5 * probD) qph[i, ] <- pnorm((0.5 * probD) - c) }

Comment:  get the posterior distributions of the intercepts, transformed to rate scale 
Category: Statistical Modeling
Code:
post.description <- inv_logit_scaled(posterior_samples(m.studies, 'b_intercept'))[,1] post.evidence    <- inv_logit_scaled(posterior_samples(m.studies, 'b_intercept') + posterior_samples(m.studies, 'b_conditionDescriptionPlusEvidence'))[,1]

Comment: add the observed average accuracy per study and per condition
Category: Data Variable
Code:
fit$obs.accuracy <- c(aggregate(dat$guessed.correctly, list(condition = dat$condition), mean)[,'x'], aggregate(dat$guessed.correctly, list(study = dat$study, condition = dat$condition), mean)[,'x'])
File: Gyurkovics_Stafford_Levita_analyses.R

Comment: Create a binary trial type variable 0  Go, 1  No Go 
Category: Data Variable
Code:
sart$trial_type <- sart$code sart$trial_type[sart$code == 3] <- NA sart$trial_type <- as.factor(sart$trial_type-1)

Comment: Calculate Go RT coefficient of variation (CV) to index intraindividual variability
Category: Statistical Test
Code:
sartsub$go_cv <- sartsub$gosd / sartsub$gomean sart <- merge(sart, sartsub[,c(1,5,6,9)], by = "subid")

Comment: Add CSE variables to the MW probe data set
Category: Data Variable
Code:
probes <- merge(probes, cse_wide[,c("subid","cse","ce","csez","cez")], by = "subid")
File: osylv_sitecomparison.R

Comment:  read in, display, and summarize 'csv' data 
Category: Data Variable
Code:
data_raw <- read.table("osylv_spaceuse_raw.csv", header = T, sep =",") head(data_raw)

Comment: Add collumns with delta distance and delta time
Category: Data Variable
Code:
tracks <- tracks %>% group_by(id) %>% mutate(time_diff = difftime(dt, lag(dt, n = 1L), units = "min"), delta_x = x_utm - lag(x_utm, n = 1L), delta_y = y_utm - lag(y_utm, n = 1L), dist = sqrt(delta_x^2+delta_y^2))

Comment: boxplot of maximum dist per id
Category: Visualization
Code:
maxdist_plot <- ggplot(daily_perid, aes(x= sex, y=max_dist_perid, fill = sex)) + theme_bw(20) + geom_boxplot(aes(fill = sex), outlier.shape = NA) + labs(y = "Longest movement (m)") + geom_jitter(aes(fill=sex), position=position_jitterdodge(0.2), shape = 21, size = 4, alpha=0.4) + facet_wrap(~site, labeller = labeller( site=c(can ="Natural site", oto = "Enclosures"))) + scale_x_discrete(labels= c("F", "M")) + theme(legend.position= "none", axis.title.x = element_blank(), axis.ticks.x = element_blank(), axis.text.x = element_text(color = "black", size = 18), aspect.ratio = 3) + ylim(0, 25) # excludes one male point at >40m from Canande maxdist_plot
File: helper.R

Comment: centering a variable to a range from 0.5 to 0.5
Category: Data Variable
Code:
center <- function(x) { minimum <- min(x) maximum <- max(x) return((x - (minimum + maximum)/2)/(maximum - minimum)) }
File: bivariate_model_winter_revision.R

Comment: keep only data from 2003 onwards (because fid started in 2003)
Category: Data Variable
Code:
survival <- subset(survival, year >2002)
File: all_navigation_models.R

Comment:  identify influenial points (e.g., cooksD > 6/n) 
Category: Statistical Modeling
Code:
influential_obs <- as.numeric(names(cooksD)[(cooksD > (6/n))])