[R] scoping problem

Sandy Weisberg sandy at stat.umn.edu
Wed Oct 24 21:43:58 CEST 2007


I would like to write a function that computes Tukey's 1 df for 
nonadditivity.  Here is a simplified version of the function I'd like to 
write:  (m is an object created by lm):

tukey.test <- function(m) {
  m1 <- update(m, ~.+I(predict(m)^2))
  summary(m1)$coef
  }

The t-test for the added variable is Tukey's test.  This won't work:

data(BOD)
m1 <- lm(demand~Time,BOD)
tukey.test(m1)

Error in predict(m) : object "m" not found

This function doesn't work for two reasons:
	1. The statement m1 <- update(m, ~.+I(predict(m)^2)) can't see 'm' in 
the call to predict.
	2. If in creating m missing values had been present, then predict(m), 
even if it could be computed, could be of the wrong length.

Can anyone help?



-- 
Sanford Weisberg, sandy at stat.umn.edu
Office and mailing address:
University of Minnesota, School of Statistics
312 Ford Hall, 224 Church St. SE, Minneapolis, MN  55455
612-625-8355, FAX 612-624-8868

St. Paul office:
146 Classroom-Office Building, 612-625-8777



More information about the R-help mailing list