[R] No predict method for hbrfit

varin sacha v@r|n@@ch@ @end|ng |rom y@hoo@|r
Sun Mar 22 13:54:39 CET 2020


Hi Jeff, 
Hi David,

Thanks for your responses. As the predict function does not work with hbrfit, I have tried  something without the predict function. There is an error message (Error in .subset2(x, i, exact = exact)) unclear to me. Many thanks for your help.

# # # # # # # # # # # # # # # # # # # # # # # #
install.packages( "boot",dependencies=TRUE )
install_github("kloke/hbrfit") 
install.packages('http://www.stat.wmich.edu/mckean/Stat666/Pkgs/npsmReg2_0.1.1.tar.gz') 
install.packages( "robustbase",dependencies=TRUE )
install.packages( "quantreg",dependencies=TRUE  )

library(robustbase)
library(quantreg)
library(boot)
library(hbrfit)

n<-50
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)
HBR<-hbrfit(y_obs ~ b+z+a)

# function to obtain MSE
MSE <- function(data, indices, formula) {
    d <- data[indices, ] # allows boot to select sample
    fit <- hbrfit(formula, data = d)
    ypred <- y_model
   mean((d[[HBR$fitted.values]]-ypred)^2)
 }

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

str(results)

boot.ci(results, type="bca" )
# # # # # # # # # # # # # # # # # # # # # # # #
 

Le dimanche 22 mars 2020 à 01:42:49 UTC+1, David Winsemius <dwinsemius using comcast.net> a écrit : 






On 3/21/20 4:09 PM, varin sacha via R-help wrote:
> Dear R-helpers,
>
> Using the HBR (high breakdown rank-based) robust estimator and the hbrfit function, I get an error saying Error in UseMethod("predict") for hbrfit. How can I solve the problem ? Many thanks for your help.


What makes you think there is a predict method for objects returned by 
hbrfit?

(I'm also puzzled how one would construct such a prediction. How would 
one construct an estimate of something based on a weighted Wilcoxon 
scale when the weighting depends on the original data? What weights 
would apply to the new data?)


I do note that there are residuals in the object returned from 
https://github.com/kloke/hbrfit/blob/master/R/hbrfit.R


Perhaps you can do something with that?

-- 

David


>
> # # # # # # # # # # # # # # # # # # # # # # # #
> install.packages( "robustbase",dependencies=TRUE )
> install.packages( "boot",dependencies=TRUE )
> install.packages( "MASS",dependencies=TRUE  )
> install.packages( "quantreg",dependencies=TRUE  )
> install.packages( "RobPer",dependencies=TRUE  )
> install_github("kloke/hbrfit")
> install.packages('http://www.stat.wmich.edu/mckean/Stat666/Pkgs/npsmReg2_0.1.1.tar.gz')
> install.packages( "RobStatTM",dependencies=TRUE )
>
> library(boot)
> library(robustbase)
> library(MASS)
> library(quantreg)
> library(RobPer)
> library(hbrfit)
> library(RobStatTM)
>
> 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 <- hbrfit(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 = y_obs ~ 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.


______________________________________________
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