0

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;

  • 1
    first, when using `subset`, do not use `$` – Onyambu Apr 28 '21 at 01:23
  • use `subset(data , Treatment==treatment)` – Onyambu Apr 28 '21 at 01:31
  • `boot` seems to be a function in many different packages. What package specifically are you using? It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Apr 28 '21 at 01:44
  • @Onyambu Thank you for the suggestion. The problem still happens after this minor change. – Pedro Brandão Dias Apr 28 '21 at 12:21
  • @MrFlick ty for the suggestion. I have added package information and included a minimal csv dataset for testing. Let me know if you need any other info for reproducing it. – Pedro Brandão Dias Apr 28 '21 at 12:35

1 Answers1

0

Any chance the upper case "T" in "data$Treatment" is causing you issues?

mikephel
  • 30
  • 6
  • No. The data frame column is called Treatment with a capital t. I called the argument treatment without capital on purpose to differentiate it. I have tried to call the argument something else (treat, tr), and I get the same error. – Pedro Brandão Dias Apr 28 '21 at 03:06