I wrote a function to calculate PAFPM2.5
This function works fine.
However, there is a fatal error in my last step where I try to apply the function to a set of vector values. In the first line of the code, I manually put values and there the code works correctly. But I don't need 1 value, but i need PAFPM2.5 for hundreds of value, whereby RR.low, RR.up and RR.est are read from a vector as you can see in the 2nd line of the code.
Unfortuantely, This results in an error : "Error in PAF.summary(low = sectors$RR.low, up = sectors$RR.up, est = sectors$RR.est) : unused arguments (low = sectors$RR.low, up = sectors$RR.up, est = sectors$RR.est)"
For clarity, sectors$RR.low contains around 100 RR.low values and the same is true for the other columns.
PAFPM2.5<-PAF.summary(RR.low = 1.4, RR.up = 1.6, RR.est=1.5) #PM2.5
PAFPM2.5<-PAF.summary(low = sectors$RR.low, up = sectors$RR.up, est=sectors$RR.est) #PM2.5
##full script
library(readxl)
library(triangle)
sectors <- read_excel("sectors.xlsx") ##of handmatig inlezen via de knop (import dataset)
RR.low <- numeric()
RR.up <- numeric()
RR.est <- numeric()
RR.low <- sectors$RR.low
RR.up <- sectors$RR.up
RR.est <- sectors$RR.est
PAF.summary<-function(RR.low,RR.up,RR.est){
### RR.est is the point estimate of the RR
### (RR.low,RR.up) is the CI of the RR
# relative risk
r <- rtriangle(10000,a=RR.low,b=RR.up,c=RR.est)
# proportion of population with risk factor
p<-1.0 #in a statistical sector, 100% exposed to mean concentration within sector
# traditional PAF method
PAF<-(p*(r-1))/(p*(r-1)+p)
return(quantile(PAF,c(0.025,0.5,0.975)))
}
PAFPM2.5<-PAF.summary(RR.low = 1.4, RR.up = 1.6, RR.est=1.5) #PM2.5 ###works fine
##should be converted to store many values based on the sectors file
PAFPM2.5<-PAF.summary(RR.low = sectors$RR.low, RR.up = sectors$RR.up, RR.est=sectors$RR.est) #PM2.5