JKR
JKR

Reputation: 11

Bootstrapping non linear regression in R (mgcv/gam)

I am trying to bootstrap a non-linear regression (produced with the mgcv package) in R, where residuals from the regression are significantly skewed. In this instance, ideally to produce a p value.

When I do this on a linear regression model, it works fine. I have been using the boot_summary command from the "boot.pval" package:

linear <-  lm(y ~ x1 + x2 + x3)

boot_summary <- boot_summary(linear, R= 200000, method="case")

However this, and various other bootstrapping methods I have found, do not work for a non linear regression produced with mgcv.

nonlinear <-  gam(y ~ s(x1, bs="tp") + (x2, bs="tp") + (x3, bs="tp"))

boot_summary <- boot_summary(nonlinear, R= 200000, method="case")

I get a "Residual bootstrap is not implemented in the 'car' function 'Boot'. Use the 'boot' function in the 'boot' package to write..." error.

I have tried this in the boot package too without success, using various variations on the below:

# Bootstrap 95% CI for R-Squared
library(boot)
# function to obtain R-Squared from the data
rsq <- function(formula, data, indices) {
  d <- data[indices,] # allows boot to select sample
  fit <- lm(formula, data=d)
  return(summary(fit)$r.square)
}
# bootstrapping with 1000 replications
results <- boot(data=mtcars, statistic=rsq,
   R=1000, formula= y ~ s(x1)+ s(x2))

# view results
results
plot(results)

Is this possible with a non linear regression produced with mgcv?

Any assistance would be much appreciated.

Thank you.

Upvotes: 1

Views: 349

Answers (0)

Related Questions