I have a bunch of raster calculations that are working, but there must be a more efficient way to do this with a do-loop or function.
Essentially I have a bunch of combinations of: rates (county level, zip level, etc), which correspond with age group, population datasets for each age group, two sets of concentration data sets, and multiple betas and lower and upper confidence intervals for the betas. I am running the below attributable fraction calculation.
y = rate * population * (1-exp(-beta*concentration))
It's not important to know exactly which combinations I have to run, just that there are a lot of them. I have tried if statements that haven't worked, functions using (i in length) which haven't worked, and multiplying stacked rasters (stacks of the rates, stacks of the pollutants, vectors of the betas, etc).
Doing this for every combination, lower and upper confidence intervals, etc, is not efficient and I am bound to make mistakes.
Is there a straightforward way to get started?
INPUTS - all are on the same resolution, extent, cell size.
#Population rasters adult.pop all.pop eld.pop #Rates zip.all # Zip, all ages, all-cause, rate per 10,000 cbg.25 # CBG, ages 25-99 years, all-cause, rate per 10,000 cbg.65 # CBG, ages 65-99 years, all-cause, rate per 10,000 co.all # County, all ages, all-cause, rate per 10,000 co.25 # County, ages 25-99 years, all-cause, rate per 10,000 co.65 # County, ages 65-99 years, all-cause, rate per 10,000 #Pollutants no2.v1 # V1 concentration no2.v2 # V2 concentration #Stack rates by age group rates.adult <- stack(cbg.25, co.25) rates.all <- stack(zip.all, co.all) rates.eld <- stack(cbg.65, co.65) #Betas beta.adult <- 0.002078254 adult.lower <- 0.000598207 adult.upper <- 0.003536714 elderly.lower <- 0.001105454 elderly.upper <- 0.001365306
# (1) V1 concentration elderly.1 <- eld.pop*rates.eld*(10^-4)*(1-exp(-beta.eldery*no2.1)) # (2) V2 concentration elderly.2 <- eld.pop*rates.eld*(10^-4)*(1-exp(-beta.elderly*no2.2))