[R] using jackknife in linear models
Simon Knapp
sleepingwell at gmail.com
Fri Dec 19 05:56:47 CET 2008
The definition of jackknife implies that the result of theta must be a
numeric scalar. So, presuming you wanted to jackknife a coefficient,
theta would need to be something like:
theta <- function(x, xdata, coefficient) coef(lm(model.lm,
data=xdata[x,]))[coefficient]
and would be called something like:
results <- jackknife(1:n,theta,xdata=DF,coefficient="(Intercept)")
To do all coefficients, you could write a function like like:
jackknife.apply <- function(x, xdata, coefs) sapply(coefs,
function(coefficient) jackknife(x, theta, xdata=xdata,
coefficient=coefficient), simplify=F)
and call it like:
results <- jackknife.apply(1:n, DF, c("(Intercept)", "V1", "V2", "V3"))
which would give you a list with the jackknife output for each coefficient.
note that you don't need to attach DF for your code to work :-)
Regards,
Simon Knapp.
On Fri, Dec 19, 2008 at 7:02 AM, Mark Heckmann <mark.heckmann at gmx.de> wrote:
> Hi R-experts,
>
> I want to use the jackknife function from the bootstrap package onto a
> linear model.
> I can't figure out how to do that. The manual says the following:
...
> So I tried:
>
> DF <- as.data.frame(matrix(rnorm(250), ncol=5))
> attach(DF)
> model.lm <- formula(V1 ~ V2 + V3 + V4)
> n <- 50
> theta <- function(x, xdata){ lm(model.lm, data=xdata) }
> results <- jackknife(1:n,theta,xdata=DF)
More information about the R-help
mailing list