I am trying to boostrap a slope estimate using the boot function in the package boot . This is my function and boot code:
library(boot)
decay.rate <- function(data, treatment){
dt <- subset(data ,data$Treatment==treatment)
dt$ln<-log(dt$copies+0.09)
lm<-lm(ln~days, dt)
return(as.numeric(abs(lm$coefficients[2])))
}
boot(raw.data, decay.rate, R = 1000, treatment="60")
but I keep getting the error
Error in statistic(data, original, ...) : unused argument (original)
When I google this error, I find it is associated with people creating functions with a single argument and trying to apply it. But mine takes two arguments (data, treatment), and uses both. When I test the function, it works and seems to be sensitive to both arguments. For example:
> decay.rates(raw.data, "60")
[1] 2.476477
> decay.rates(raw.data, "N")
[1] 2.398521
By using other methods I know those answers to be correct, so the function is working as expected. Also, when I remove the argument altogether, I get an error with my custom function, telling me that it is in fact being used:
> boot(raw.data, decay.rates, R = 1000)
Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) :
0 (non-NA) cases
This person had a similar problem, caused by them calling an older version of the function by accident. so I have tried the solution that worked for them - rm(list = ls()) - without success.
What am I doing wrong? I appreciate any help.
Here is a minimal dataset to test with:
Treatment,copies,days N,18.5,0.03 N,20.2,0.03 60,10.8,0.03 60,9.8,0.03 N,13.4,0.25 N,11.6,0.25 60,5.6,0.25 60,8.6,0.25 N,1.2,0.75 N,3.2,0.75 60,1.8,0.75 60,5.6,0.75 N,0,2 N,0,2 60,0,2 60,0,2
cheers;