[R] Error in FastTau(formula, data = d) : unused argument(s) (data = d)

Rui Barradas ru|pb@rr@d@@ @end|ng |rom @@po@pt
Sun Mar 22 10:59:46 CET 2020


Hello,

1. There is no need to install package 'boot', it's a base package.
2. The question.

The problem is that FastTau returns an object of class "list" and there 
is no 'predict' method for lists, you will have to define your own.
This is easy, it's just a matrix multiply.
And you are not calling FastTau correctly, see the function 
documentation and the new MSE function below.



MSE <- function(data, indices, formula){
   predfun <- function(object, model){
     beta <- object[["beta"]]
     as.vector(model %*% beta)
   }
   d <- data[indices, ] # allows boot to select sample
   modmat <- model.matrix(as.formula(formula), data = d)
   fit <- FastTau(x = modmat, y = d[["y_obs"]])
   ypred <- predfun(fit, modmat)
   mean((d[["y_obs"]]-ypred)^2)
}

# Make the results reproducible
set.seed(1234)
# bootstrapping with 10 replications
results <- boot(data = df, statistic = MSE,
                 R = 10, formula = ~b+z+a)

type <- c("norm","basic", "stud", "perc", "bca")
boot.ci(results, type = type[-5])


Hope this helps,

Rui Barradas

Às 23:14 de 21/03/20, varin sacha via R-help escreveu:
> Dear R-helpers,
> 
> Another problem with FastTau function from the RobPer packages. Any solution to solve my problem would be highly appreciated.
> 
> 
> # # # # # # # # # # # # # # # # # # # # # # # #
> install.packages( "boot",dependencies=TRUE )
> install.packages( "RobPer",dependencies=TRUE  )
> 
> library(boot)
> library(RobPer)
> 
> n<-200
> b<-runif(n, 0, 5)
> z <- rnorm(n, 2, 3)
> a <- runif(n, 0, 5)
> 
> y_model<- 0.1*b - 0.5 * z - a + 10
> y_obs <- y_model +c( rnorm(n*0.9, 0, 0.1), rnorm(n*0.1, 0, 0.5) )
> df<-data.frame(b,z,a,y_obs)
> 
>   # function to obtain MSE
>   MSE <- function(data, indices, formula){
>      d <- data[indices, ] # allows boot to select sample
>      fit <- FastTau(formula, data = d)
>      ypred <- predict(fit)
>     mean((d[["y_obs"]]-ypred)^2)
>   }
>   
> # Make the results reproducible
>   set.seed(1234)
>   
>   # bootstrapping with 600 replications
>   results <- boot(data = df, statistic = MSE,
>                    R = 600, formula = model.matrix(~b+z+a))
> str(results)
> 
> boot.ci(results, type="bca" )
> # # # # # # # # # # # # # # # # # # # # # # # # #
> 
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list