pufftissue pufftissue
2008-Dec-05 06:42 UTC
[R] How to add ability to ignore NA values to my own function?
Hi,
I obtained custom code for the infamous HL test, which I know is frowned
upon here.
In any event, I'm feeding it a matrix and a data frame. How can I set the
function to ignore missing values?
I tried:
HL <- function(p, y, NA.rm=T)
{
options(na.action=na.exclude)
y <- y[order(p)];
p <- p[order(p)];
n <- length(p);
idx <- (0:(n-1)) %/% (n/10);
R.decile <- 0;
for (i in 0:9)
{
ybar <- sum(y[idx==i]) ;
m <- sum(idx==i) ;
pbar <- mean(p[idx==i]) ;
R.decile <- R.decile + (ybar - m*pbar)^2/(m*pbar*(1-pbar));
}
print(paste("HL Decile:", R.decile, ", P=", 1 -
pchisq(R.decile, df=8)));
}
Thank you!
[[alternative HTML version deleted]]