drndr/statcodesearch huggingface dataset:
File: simpd_helper.R

Comment:  Models   .. Contrasts   (Reverse) Helmert for cond speech, cond mask  Treatment for speech_mask  Sum for group  Factor variables 
Category: Statistical Modeling
Code:
df <- df %>% mutate( group = factor(group), # oc, pd gender = factor(intake_gender), # f, m cond_mask = factor(cond_mask, levels = c("nm","sm","kn")), cond_speech = factor(cond_speech, levels = c("habitual","clear","loud")) ) %>% mutate(speech_mask = paste(cond_speech,cond_mask,sep="_")) levels(df$group) # oc, pd levels(df$gender) # f, m levels(df$cond_speech) # habitual, clear, loud levels(df$cond_mask) # nm, sm, kn
File: dataAnalysisRewardAppsSurvey.R

Comment: 4) Descriptives and data inspection   total duration on survey
Category: Data Variable
Code:
stat.desc(working_file %>% group_by(pp) %>% slice(1) %>% pull(duration))

Comment: bayesian ttests
Category: Statistical Test
Code:
ttestBF(wide$high, wide$neutral, paired = TRUE) ttestBF(wide$low, wide$neutral, paired = TRUE) ttestBF(wide$high, wide$low, paired = TRUE) formatC(3057348376, format = "e", digits = 2)
File: fill_summary_table.R

Comment: Confidence interval as a vector
Category: Statistical Modeling
Code:
result <- c("lower" = vec_mean - error, "upper" = vec_mean + error) return(result) }
File: expertsurvey_CDRCCS.R

Comment: Transform academic background and job category variables from character to factor
Category: Data Variable
Code:
class(expertsample$acadgroup) expertsample$acadgroup<-as.factor(expertsample$acadgroup) class(expertsample$job_cat) expertsample$job_cat <- as.factor(expertsample$job_cat)

Comment: graphical check for normal distribution of differences support (mean)
Category: Visualization
Code:
diff_support <- bothexpert$BECCS_support-bothexpert$DACCS_support hist(diff_support)

Comment: Wilcoxon tests support (mean)
Category: Statistical Test
Code:
wilcox.test(bothexpert$BECCS_support, bothexpert$DACCS_support, paired=TRUE)
File: Study2A_analyses.R

Comment: correlations separately for each condition
Category: Data Variable
Code:
data_con <- data[data$Cond == "Control", ] data_ent <- data[data$Cond == "Entitlement", ] chart.Correlation(data_con[ , c("pes","prestige","dominance","benign","malicious","pain")], use = "pairwise.complete.obs", pch = 20, histogram = TRUE) chart.Correlation(data_ent[ , c("pes","prestige","dominance","benign","malicious","pain")], use = "pairwise.complete.obs", pch = 20, histogram = TRUE) rm(data_con,data_ent)
File: educationnetworksatleast6.R

Comment: Estimate partial correlation matrices using fiml (partial cors and not glasso b/c different sample sizes leads to different glasso penalties)
Category: Statistical Modeling
Code:
net1hi <- cor1.edhi$cor %>% EBICglasso(., n = cor1.edhi$n) net2hi <- cor2.edhi$cor %>% EBICglasso(., n = cor2.edhi$n) net3hi <- cor3.edhi$cor %>% EBICglasso(., n = cor3.edhi$n) net4hi <- cor4.edhi$cor %>% EBICglasso(., n = cor4.edhi$n) net5hi <- cor5.edhi$cor %>% EBICglasso(., n = cor5.edhi$n) net6hi <- cor6.edhi$cor %>% EBICglasso(., n = cor6.edhi$n) net7hi <- cor7.edhi$cor %>% EBICglasso(., n = cor7.edhi$n) net1lo <- cor1.edlo$cor %>% EBICglasso(., n = cor1.edlo$n) net2lo <- cor2.edlo$cor %>% EBICglasso(., n = cor2.edlo$n) net3lo <- cor3.edlo$cor %>% EBICglasso(., n = cor3.edlo$n) net4lo <- cor4.edlo$cor %>% EBICglasso(., n = cor4.edlo$n) net5lo <- cor5.edlo$cor %>% EBICglasso(., n = cor5.edlo$n) net6lo <- cor6.edlo$cor %>% EBICglasso(., n = cor6.edlo$n) net7lo <- cor7.edlo$cor %>% EBICglasso(., n = cor7.edlo$n)
File: YCAS_Scale_development.R

Comment:  5. Confirmatory Factor analysis To replicate our results without item 1, delete yts_1 from the analyses 5.1 yes/no RESIST 
Category: Statistical Modeling
Code:
dataCFA1 <- na.omit(data.frame(data$id,data$yts_1, data$yts_2, data$yts_3, data$yts_4,  data$yts_5, data$yts_6,  data$yts_7, data$yts_8,  data$yts_9, data$yts_10, data$yts_11, data$yts_12, data$yts_13)) colnames (dataCFA1) <-c("id","yts_1","yts_2","yts_3","yts_4","yts_5","yts_6", "yts_7","yts_8","yts_9","yts_10","yts_11","yts_12", "yts_13") model1 <- 'EA =~ yts_1 + yts_2  + yts_3  +  yts_4  + yts_5 + yts_6  + yts_7  +  yts_8  + yts_9 + yts_10 + yts_11 +  yts_12 + yts_13' fit1 <- cfa(model1, data=dataCFA1, meanstructure=T, std.lv=T, estimator = "WLSMV", ordered = c("yts_1", "yts_2",  "yts_3",  "yts_4", "yts_5", "yts_6",  "yts_7",  "yts_8", "yts_9", "yts_10", "yts_11", "yts_12", "yts_13")) summary(fit1, fit.measures=TRUE, standardized = T) fitMeasures(fit1,c("chisq","df","pvalue","cfi","tli","rmsea", "wrmr",'rmsea.ci.lower','rmsea.ci.upper')) modindices(fit1, sort. = T)

Comment: get factorscores and include them in origingal data
Category: Data Variable
Code:
dataCFA1$factorscore1 <- predict(fit1) data <- left_join(data, dataCFA1,  by = "id") data$factorscore1 dataCFA3$factorscore3 <- predict(fit3) data1 <- left_join(data1, dataCFA3,  by = "record_id") data1$factorscore3 dataCFA4$factorscore4 <- predict(fit4) data1 <- left_join(data1, dataCFA4,  by = "record_id") data1$factorscore4
File: 1_dataPrep.R

Comment: join behDat and demDat
Category: Data Variable
Code:
allData = inner_join(behDat, demDat, by = "userCode")

Comment: Standardize Variables  zscoring
Category: Data Variable
Code:
df_overall = df df_overall$sWM = scale(df_overall$sWM) df_overall$rtWM = scale(df_overall$rtWM) df_overall$rtDivAtt = scale(df_overall$rtDivAtt) df_overall$rtAlert = scale(df_overall$rtAlert) df_overall$sRWT = scale(df_overall$sRWT)

Comment:  Remove time points above 29, because not everyone attended that often  
Category: Data Variable
Code:
df_overall = df_overall %>% filter(Time < 29) %>% ungroup()

Comment: ensure that userCode is a factor
Category: Data Variable
Code:
df_overall$userCode = as.factor(df_overall$userCode)
File: DM_a_k.R

Comment: We can also try to cluster the languages based on the feature values they have. We currently use hierarchical clustering. This will normally also reflect the PCA visualization. The output can also be compared with the family grouping of the languages.  generate the clusters
Category: Visualization
Code:
hclust_avg <- hclust(daisy(con_data)) hclust_avg <- hclust(daisy(con_data))

Comment: add squares around the clusters
Category: Visualization
Code:
rect.hclust(hclust_avg , k = 4, border = 1:4) rect.hclust(hclust_avg , k = 4, border = 1:4)

Comment:  Extracting distances  We can extract the pairwise distance between the points of the data set. First, we can visualize the distances in a twodimensional space. Normally, we expect that this visualization matches the output of the PCA.  change the content to a distance matrix 
Category: Visualization
Code:
distances <- con_data %>% dist(method = "euclidean") distances <- con_data %>% dist(method = "euclidean")
File: Schizotypal Ambivalence.R

Comment: recodes ethnicity (Decline/Other category is set to missing)
Category: Data Variable
Code:
sambdif<-samb %>% select(1:19, SAmb_tot, gender, ethnic) %>% mutate(ethnic_fac = rec(ethnic, rec = "1=0;; 6=NA;; else=1")) %>% convert(fct(gender, ethnic_fac)) table(sambdif$gender) # 0=women, 1=men table(sambdif$ethnic_fac) #0=EuroAm, 1=PoC
File: 04_clusters2_tvals.R

Comment: reorder the list of results to match the alignment of the dendrogram
Category: Visualization
Code:
list.res.reo<-list.res[order.dendrogram(dend1)] layd<-c(10,1) tiff("Figure_hclust2.tif",width=sum(layd),height=11.5,units="cm",res=600,compression="lzw") layout(matrix(1:2,nrow=1),widths=layd) par(mar=c(3.5,1,1.5,14),mgp=c(2,0.8,0)) plot(dend1, cex = 0.8, horiz=T,xlab="Height")
File: plotting_style.R

Comment: function to read in cleaned data and format  it as a tibble that can be used for plotting
Category: Visualization
Code:
read_data_for_plotting <- function(data_path) { dat <- read_csv(data_path, col_types = cols())
File: Cluster analysis non-refined factor scores.R

Comment: create a matrix of relevant item loadings to calculate nonrefined factor (scale) scores
Category: Statistical Modeling
Code:
scaleMatrix <- data.frame(data = matrix(EFA$loadings, ncol = 6)) scaleMatrix <- lapply(scaleMatrix, function(x) ifelse(x >= 0.4, 1, ifelse(x <= -0.4, -1, NA))) scaleMatrix <- data.frame(data = scaleMatrix, row.names = colnames(mainData[, c(2:56)])) colnames(scaleMatrix) <- c("Sensory", "CognitiveDemand", "ThreatToSelf", "CrossSettings", "Safety", "States")
File: 03_table_comorbidities_by_study.R

Comment: get number of patients (from 'table_overview_of_studies.R')
Category: Data Variable
Code:
df_long <- left_join(df_long, tab_study_overview %>% select(study_name, N_Patients) %>% rename(Study = study_name) %>% mutate(N_Patients = as.numeric(str_extract(N_Patients, '(\\d*)'))), by = 'Study')
File: Code_LMMs_BestPractice_Example_withOutput.R

Comment: add error bars with standard error
Category: Visualization
Code:
plot <- plot + geom_errorbar(aes(ymin=lower,ymax=upper),width=.2) plot <- plot + ggtitle("2a) Average accuracy across four Cue Type conditions")
File: 3_IRT.R

Comment:  Run IRT model: 3dim model for math, read  and scie, no weights  Possibility to set seeds and iteration number in the function parameter 
Category: Statistical Modeling
Code:
mod <- run.irt(pa12_resp_s, items = item.dif)
File: ConfirmatoryAnalyses.R

Comment: function to create tick marks on a logscale
Category: Visualization
Code:
log10Tck <- function(side, type){ lim <- switch(side, x = par('usr')[1:2], y = par('usr')[3:4], stop('side argument must be "x" or "y"')) at <- floor(lim[1]) : ceiling(lim[2]) at <- 0:8 return(switch(type, minor = outer(1:9, 10^(min(at):max(at)))[,1:8], major = 10^at, stop('type argument must be "major" or "minor"') )) } if(saveFigures) cairo_ps(file = '../R_Output/Images/OriginalBFScatter.eps', onefile = TRUE, fallback_resolution = 600, width = 7.3, height = 4.16)

Comment: Plot: original Bayes factor and replication effect size
Category: Visualization
Code:
plot(original.bf, replication.effectsizes, xlim    = c(1, 10^8), ylim    = c(-0.2, 1), axes    = FALSE, log     = 'x', cex     = 2, cex.lab = 1.6, pch     = 21, bg      = c('grey36', 'grey')[replication.outcomes], xlab    = 'Bayes Factor Original Study', ylab    = 'Replication Effect Size (r)')

Comment:  take the xaxis indices and add a jitter, proportional to the N in each level 
Category: Data Variable
Code:
myjitter <- jitter(rep(i, length(thisvalues)), amount=levelProportions[i]/6) points(myjitter, thisvalues, pch=1, col=rgb(0,0,0,.9), cex = 1.5, lwd = 1.5) } graphics.off() rm(myjitter, thislevel, thisvalues, mylevels, levelProportions, nsubjects, subjects)
File: code.R

Comment: Multiple Regression Analysis
Category: Statistical Modeling
Code:
multreg.second(Speaking ~ Vocabulary+Grammar+Writing+Reading, corr=correl, n=100) multreg.second(Y~ X1+X2+X3, corr=correl, n=100) multreg.second(Score~ Wordcount+CLI+Commas+Stopwords+Linking+WordsSentence, corr=correl, n=200) multreg(Score~ Wordcount+CLI+Commas+Stopwords+Linking+WordsSentence, data=dat1) lm.out <- lm(Score ~., dat1)

Comment: Dominance Analysis (using dominanceanalysis package)
Category: Statistical Modeling
Code:
lm.cov <- lmWithCov(Score ~ Wordcount+CLI+Commas+Stopwords+Linking+WordsSentence, correl) da <- dominanceAnalysis(lm.cov) print(da)
File: ECoach Functions.R

Comment: FUnctions for Cleaning   Function to generate a table with all observations within a variable and its corresponding count
Category: Data Variable
Code:
check_observation <- function (df, column) { require (tidyverse) check <- df %>% group_by (as.vector(unlist(df[, column]))) %>% count () colnames(check)[1] <- column return (check) } recur.collapse <- function(df, n = ncol(df)) { #collapse function combine <- function(x,y){ if(!is.na(x)){ return(x) } else if (!is.na(y)) { return(y) } else { return(NA) } } if(n==1){ return(df[,1]) } else { return(mapply(combine, df[,n], recur.collapse(df, n-1))) } } multi_spread <- function(df, id, key, var){ require(gtools) require(tidyverse) df.list <- lapply(var, function(x){ df.temp <- spread(df[, c(id, key, x)], key, x) # spread 1 variable cname <- mixedsort(unique(as.vector(unlist(df[,key])))) # sort colnames in alphanumeric order df.temp <- df.temp[, c(id, cname)] # rename column names colnames(df.temp)[2:ncol(df.temp)]  <- paste(x, colnames(df.temp[,cname]), sep= "_") #add key to column names return(df.temp) }) df.output <- df.list[[1]] # initialise for(i in 1:(length(var)-1)){ # combine matrices together df.output <- full_join(df.output, df.list[[i+1]]) } return(as.data.frame(df.output)) }
File: Exp2.R

Comment: Extract posteriors of effects from Bayesian ANOVA
Category: Statistical Modeling
Code:
bestmod <- modBF[1] chains <- posterior(bestmod, iterations=50000, columnFilter="^Subject$") colnames(chains)
File: P2_analysis_oldbins.R

Comment: STATISTICAL TEST: Nonparametric Spearman's correlation nonnormalized conditional entropy
Category: Statistical Test
Code:
cor.test(results$DATE, results$CEDenominationsMotifs, method = "spearman") rdates <- rev(dates) #dates = centuries BCE plot(results$DATE, results$CEDenominationsMotifs, xlim = c(6,4), xaxt='n', xlab = "Century BCE", ylab = "H(D|d)", main = "P2: Conditional entropy of denominantions given designs") axis(1, at = rdates, labels = rdates)

Comment: ____________________________________________________________ Plots with H(D|d)  nonnormalized conditional entropy Getting statistics: mean, meadian, standard deviation among authorities per period for nonnormalized conditional entropy of denomination given designs 
Category: Visualization
Code:
N <- aggregate(CEDenominationsMotifs ~ DATE, data = resultspoleis, FUN = length) MEAN <- aggregate(CEDenominationsMotifs ~ DATE, data = resultspoleis, FUN = mean) MEDIAN <- aggregate(CEDenominationsMotifs ~ DATE, data = resultspoleis, FUN = median) SD <- aggregate(CEDenominationsMotifs ~ DATE, data = resultspoleis, FUN = sd) resultspoleis_summary <- cbind.data.frame(N, MEAN$CEDenominationsMotifs, MEDIAN$CEDenominationsMotifs, SD$CEDenominationsMotifs) colnames(resultspoleis_summary) <- c("DATE","N","MEAN","MEDIAN","SD") resultspoleis_summary$SE <- resultspoleis_summary$SD / sqrt(resultspoleis_summary$N)

Comment: Getting statistics: mean, meadian, standard deviation among authorities per period for normalized conditional entropy of denomination given designs 
Category: Statistical Modeling
Code:
N <- aggregate(NormCEDenominationsMotifs ~ DATE, data = resultspoleis, FUN = length) MEAN <- aggregate(NormCEDenominationsMotifs ~ DATE, data = resultspoleis, FUN = mean) MEDIAN <- aggregate(NormCEDenominationsMotifs ~ DATE, data = resultspoleis, FUN = median) SD <- aggregate(NormCEDenominationsMotifs ~ DATE, data = resultspoleis, FUN = sd) Nresultspoleis_summary <- cbind.data.frame(N, MEAN$NormCEDenominationsMotifs, MEDIAN$NormCEDenominationsMotifs, SD$NormCEDenominationsMotifs) colnames(Nresultspoleis_summary) <- c("DATE","N","MEAN","MEDIAN","SD") Nresultspoleis_summary$SE <- Nresultspoleis_summary$SD / sqrt(Nresultspoleis_summary$N)
File: PairsBindingRSS_Stats.R

Comment:  aggregate data, zstandardize all predictor variables for the model 
Category: Data Variable
Code:
recogfreq <- aggregate(cbind(correct, intrusion, new) ~ id+setsize+rsizeList+rsizeNPL, data=recogdat, FUN=sum) recogfreq$zsetsize <- (recogfreq$setsize - mean(recogfreq$setsize))/sd(recogfreq$setsize) recogfreq$zrsizeList <- (recogfreq$rsizeList - mean(recogfreq$rsizeList))/sd(recogfreq$rsizeList) recogfreq$zrsizeNPL <- (recogfreq$rsizeNPL - mean(recogfreq$rsizeNPL))/sd(recogfreq$rsizeNPL) for (sc in 1:length(scales))  { prior <- paste0("cauchy(0, ", as.character(scales[sc]), ")") fixefPrior <- c(set_prior(prior, class="b")) ranefPrior <- set_prior("gamma(1,0.04)", class="sd")
File: Exp1a_Election_post.R

Comment: Cronbach's alpha (ingroup)
Category: Statistical Test
Code:
iden.ing.woOutliers.a <- c("ingroup.value", "ingroup.like", "ingroup.connected") iden.ing.woOutliers <- data.all[iden.ing.woOutliers.a] cronbach(iden.ing.woOutliers)
File: quest_analyses.R

Comment:  min and max age, mean and sd age, percentage of men and women 
Category: Data Variable
Code:
minAge = min(df_preQ$age) maxAge = max(df_preQ$age) meanAge = mean(df_preQ$age) sdAge = sd(df_preQ$age) females = length(which(df_preQ$gender == "female")) males = length(which(df_preQ$gender == "male")) other = length(which(df_preQ$gender == "other"))

Comment: Check normality with QQ plot and ShapiroWilk test  Build the linear model
Category: Statistical Test
Code:
model  <- lm(FW ~ condition, data = df_postQ)

Comment: Question 4: pearson correlation between the different subscales
Category: Statistical Test
Code:
df_cor <- data.frame(df_postQ$FW, df_postQ$DU, df_postQ$DET) colnames(df_cor) <- c('FW', 'DU', 'DET') res_cor <- rcorr(as.matrix(df_cor))

Comment: Visualize correlations  Insignificant correlations are leaved blank
Category: Visualization
Code:
corrplot(res_cor$r, method = 'number', type="upper", order="hclust", p.mat = res_cor$P, sig.level = 0.05, insig = "blank")

Comment: Stepwise regression model
Category: Statistical Modeling
Code:
step.model <- stepAIC(full.model, direction = "both", trace = FALSE) summary(step.model) step.model <- stepAIC(full.model, direction = "both", trace = FALSE) summary(step.model) step.model <- stepAIC(full.model, direction = "both", trace = FALSE) summary(step.model)
File: os_testosterone_analysis.R

Comment: Subset the data set to use base2 instead of base1 for the individuals  that have the 2nd baseline  Extract values of frogs that have two baselines
Category: Data Variable
Code:
base2_frogs <-filter(hormones, condition == "base_02")

Comment: LMER testosterone by sex and condition with interaction
Category: Statistical Modeling
Code:
m1_osT <- lmer(log(t_conc_corr) ~ sex*condition + (1|id), data = hormones)

Comment: Sex difference in Tlevel  Model plot wit sjPlot
Category: Visualization
Code:
plot_model(m1_osT_1, title = "", axis.title = "Fixed effect estimates", axis.labels = c("Time point\n (back home)", "Sex \n(male)"), dot.size = 5, line.size = 2, transform = NULL, sort.est = TRUE, colors = "gs", vline.color = "darkgrey")+ ylim(-0.5, 1) + theme_sjplot2(24)
File: diagnostic_fcns.r

Comment: now the random slopes part of the model including random intercepts and slopes and their correlation:
Category: Statistical Modeling
Code:
pot.terms.with.corr=paste(c(xnames, fe.me[modes[fe.me]!="factor"]), collapse="+")#get all fixed effects terms together... pot.terms.with.corr=paste(paste("(1+", pot.terms.with.corr, "|", re, ")", sep=""), collapse="+")#... and paste random effects, brackets and all that pot.terms.with.corr=paste(c(xnames, fe.me[modes[fe.me]!="factor"]), collapse="+")#get all fixed effects terms together... pot.terms.with.corr=paste(paste("(1+", pot.terms.with.corr, "|", re, ")", sep=""), collapse="+")#... and paste random effects, brackets and all that
File: EXPLORATORY_Gaze Following_ANALYSES.R

Comment:  Supplemental Material:  To check whether the participants followed gaze at all, we tested the gaze following score against chance level by running a one sample test against zero.  Children followed gaze in the additional gazefollowing task (M  3;; SD  1.66;; t(29)  9.89, p  .00, d  1.8).  Correlation GF & Difference Score 
Category: Statistical Test
Code:
Data$DiffSocCon <- as.numeric(Data$DiffSocCon) cor.test(Data$DS, Data$DiffSocCon, method = "pearson") #only younger
File: 01_get_gads.R

Comment: use network data only for students in classrooms with at least 50% response rate
Category: Data Variable
Code:
dat$nwinclude <- 0 dat[which(dat$prop_part > .50 & !is.na(dat$prop_part)),"nwinclude"] <- 1 length(unique(dat[which(dat$nwinclude == 1), "IDTESTGROUP_FDZ"]))    # 1708 classes with at least 50% response rate length(unique(dat[which(dat$nwinclude == 0), "IDTESTGROUP_FDZ"]))    # 290 classes excluded for network related analyses dat[which(dat$nwinclude == 0), c(nw_covariates,  grep("deg", names(dat), value = T))] <- NA #recode sociometric variables to NA for classes with low level of completeness length(unique(dat[which(dat$nwinclude == 0), "IDSTUD_FDZ"]))         # 5450 students without sociometric data length(unique(dat[which(dat$nwinclude == 1), "IDSTUD_FDZ"]))         # 36,920 students with sociometric data
File: prediction_plots.R

Comment: Reorder factor levels: (this will be useful once we create the plot legend)
Category: Visualization
Code:
dataset$trial_condition <- factor(dataset$trial_condition, levels = c("diff_3sg", "diff_3pl", "same_3sg", "same_3pl")) dataset$trial_condition_new <- factor(dataset$trial_condition_new, levels = c("different number", "same number"))

Comment: Prepare dataframe for eyetracking analysis & graphs (package eyetrackingR required)
Category: Visualization
Code:
eyetrackingr.data <- make_eyetrackingr_data(dataset, participant_column = "participant_number", trial_column = "item_nr", time_column = "time_ms_absolute", trackloss_column = "trackloss", aoi_columns = c("average_target_sample_count_proportion", "average_distractor_sample_count_proportion"), treat_non_aoi_looks_as_missing = TRUE )

Comment: Remove trackloss per trial > 50% (removed 4 trials)
Category: Data Variable
Code:
eyetrackingr.data <- clean_by_trackloss(data = eyetrackingr.data, trial_prop_thresh = .5)
File: Sentence_Level.R

Comment: check histogram for binning
Category: Visualization
Code:
hist(quop_use$t1_eff) quop_use$bins<-cut(quop_use$t1_eff,quantile(quop_use$t1_eff,p=seq(0,1,length=29),na.rm=T))

Comment: visualize with forest plot  compare corona vs. precorona
Category: Visualization
Code:
forest(lvd$est[1:16],sei=lvd$se[1:16], ilab = cbind(c("Pre-pandemic Cohorts vs. First Pandemic Cohort",rep("",7),"Pre-pandemic Cohorts vs. Second Pandemic Cohort",rep("",7)), paste0("T",rep(1:8,2)), c("Schools Open","???","???","???","Schools Closed","???","???","Alternating Lessons", "Schools Open","???","Alternating Lessons","???","???","???","???","Schools Open")), ilab.xpos = c(-1.35,-.95,-.65), ylim = c(0,22), xlim = c(-1.7,1), slab = NA, rows = c(18:11, 8:1), at = c(-.7,-.35,0,.35,.7), xlab = "Latent Variance Differences", col=c("gray","gray", "gray","gray", "black", "black", "black", "black", "gray", "gray", "black", "black", "black", "black", "black", "gray")) forest(lmd$est[1:16],sei=lmd$se[1:16], ilab = cbind(c("Pre-pandemic Cohorts vs. First Pandemic Cohort",rep("",7),"Pre-pandemic Cohorts vs. Second Pandemic Cohort",rep("",7)), paste0("T",rep(1:8,2)), c("Schools Open","???","???","???","Schools Closed","???","???","Alternating Lessons", "Schools Open","???","Alternating Lessons","???","???","???","???","Schools Open")), ilab.xpos = c(-1.35,-.95,-.65), ylim = c(0,22), xlim = c(-1.7,1), slab = NA, rows = c(18:11, 8:1), at = c(-.7,-.35,0,.35,.7), xlab = "Standardized Latent Mean Differences", col=c("gray","gray", "gray","gray", "black", "black", "black", "black", "gray", "gray", "black", "black", "black", "black", "black", "gray"))
File: 5_NMDS_comparing_dawn_and_morning_assemblage_compositions.R

Comment: to see how well the distances are measured
Category: Statistical Test
Code:
stressplot(species_matrix_short.nmds) #R2 = 0.961, linear R2 = 0.891 data.scores <- as.data.frame(scores(species_matrix_short.nmds$points)) data.scores$site <- substr(rownames(data.scores),1,6) data.scores$plots <- substr(rownames(data.scores),8,15) species.scores <- as.data.frame(scores(species_matrix_short.nmds, "species")) species.scores$species <- rownames(species.scores)

Comment: now statistical test to see if communities are statistically different from one another
Category: Statistical Test
Code:
species_matrix2 <- species_matrix %>% mutate_if(is.numeric, ~1 * (. > 0)) sp_matrix_with_group <- species_matrix2 rownames(sp_matrix_with_group) <- rownames(species_matrix) sp_matrix_with_group$grouping <- substr(rownames(sp_matrix_with_group), 7,13) ano <- anosim(species_matrix2, distance = 'euclidean', grouping = sp_matrix_with_group$grouping) summary(ano)