I have asked a very similar question recently here - lapply instead of for loop for randomised hypothesis testing r
But I now require a more simple output, and I'm struggling to tweak the previously suggested (and super helpful) code.
So,
I have observed data, and I am now randomising as above -
set.seed(42)
ID <- sample(1:30, 100, rep=T)
Trait <- sample(0:1, 100, rep=T)
Year <- sample(1992:1999, 100, rep=T)
df <- cbind(ID, Trait, Year)
df <- as.data.frame(df)
I want to group by year, and extract the overall mean n
Trait, as well as 95% CIs between groups.
Maybe something like this
df <- df %>%
group_by(Year) %>%
dplyr::summarise(
n_Trait = sum(Trait == 1),
n_total = length(Trait)) %>%
ungroup()
I now want to repeat the above x
times, and extract the mean n_Trait
and a 95%CI from those output iterations.
Very much like this, but I don't want to run the full ls model https://www.tidymodels.org/learn/statistics/bootstrap/
I hope that makes sense?