[R] Help with Bootstrap function.
Simon Wood
snw at mcs.st-and.ac.uk
Thu Jan 31 18:05:52 CET 2002
> I am using R with mcgv package to model spatial variation in density estimates of dorcas gazelle in Sinai. I have 59 points of data and 4 explanatory variables(distance from mountain edge, camel presence, Latitude & Longitude). I want to test the model fir via bootstraping. I have used the jacknife bootstraping but it have the limitation of allowing only 58 trials. I tried to use the bootstrap function in R but I couldn;t understand the help file description. Please forgive my novice with such advance statistics since I am a biologist.
> I would appreciate any help on advicing on how to use the bootstrap function in R.
> Thanks in advance
> Husam El Alqamy
- 59 datapoints is really pushing it for estimating 4 functions! You might
want to run the first bit of the code pasted below a few times to see if
this is really good enough for you [it's actually not as bad as I assumed
it was going to be].
- If you want a *really* simple bootstrap then the second part of the code
below gives an example: but for this sample size, the effect of neglecting
the bias in the fitted values and the variability in the variance estimate
will not be negligible!
- Finally, note that bootstrapping non-parametrically (i.e. case
resampling) would be a bit of a disaster in this case, since the
smoothing parameters are being selected by cross validation.
Simon.
# fit model to simulated data....
n<-59
sig2<-4
x0 <- runif(n, 0, 1)
x1 <- runif(n, 0, 1)
x2 <- runif(n, 0, 1)
x3 <- runif(n, 0, 1)
pi <- asin(1) * 2
f <- 2 * sin(pi * x0)
f <- f + exp(2 * x1) - 3.75887
f <- f + 0.2 * x2^11 * (10 * (1 - x2))^6 + 10 * (10 * x2)^3 * (1 - x2)^10-1.396
e <- rnorm(n, 0, sqrt(abs(sig2)))
y <- f + e
da<-data.frame(y=y,x0=x0,x1=x1,x2=x2,x3=x3)
b<-gam(y~s(x0)+s(x1)+s(x2)+s(x3),data=da)
plot(b,pages=1)
# now a crude parametric bootstrap....
model.mean<-fitted(b)
model.se<-b$sig2^0.5
for (i in 1:20)
{ da$y<-model.mean+rnorm(n,sd=model.se)
b.bs<-gam(y~s(x0)+s(x1)+s(x2)+s(x3),data=da)
plot(b.bs,pages=1)
}
______________________________________________________________________
> Simon Wood snw at st-and.ac.uk http://www.ruwpa.st-and.ac.uk/simon.html
> The Mathematical Institute, North Haugh, St. Andrews, Fife KY16 9SS UK
> Direct telephone: (0)1334 463799 Indirect fax: (0)1334 463748
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list