I want to perform the bootstrap function boot() to get the confidence intervals of the variable 'R_CO_GC' after grouping by the column 'BARRIER_POS' which has 3 values (after the filter).
First I defined my median function to enter the boot function:
mediana_boot <- function(x,i){
return(median(x[i]))
}
After that, I filtered the value I was not interested in from 'BARRIER_POS' and then grouped the data frame by the same variable. Later I used mutate to perform the bootstrap and calculate the confidence intervals. Then I used summarise to get the median, extract the lower and upper intervals, and keep them, alongside the median, in a data frame as a final output:
lr2_analysis_CO_FIL %>%
filter(BARRIER_POS != 'no_street') %>%
group_by(BARRIER_POS) %>%
mutate(boot_CO = boot.ci(boot(R_CO_GC, mediana_boot, R = 100), conf = 0.95, type = "bca")) %>%
summarise(mediana = median(R_CO_GC),
CI.L = boot_CO[4],
CI.U = boot_CO[5]) %>%
data.frame(mediana, CI.L, CI.U)
But sadly I got this error:
Error in cnd_bullet_header(action) : promise already under evaluation: recursive default argument reference or earlier problems?
I don't know how to solve it. Any ideas?
I would also like to add a column referring to the 3 groups (BARRIER_POS) from which I got the median and confidence intervals.
Write a function returning the confidence intervals as a tibble and apply
summarisedirectly to it.Created on 2024-03-01 with reprex v2.0.2