[R] "model.response" error

Sundar Dorai-Raj sundar.dorai-raj at pdf.com
Wed Jan 12 19:22:47 CET 2005



Bang wrote:

> When I installed R 2.0.1 (replacing 1.9.0) for Windows, a code using
> "model.response" began acting up.  Here are the first several lines of a
> code I had been tweaking for a spatial model (the code is mostly that of
> Roger Bivand--I am adapting it to a slightly different data structure and
> the problem I'm sure is with my changes, not his code).
> 
> <command name> <- function (formula, data = list(), weights, na.action =
> na.fail, type = "lag", quiet = TRUE, zero.policy = FALSE, tol.solve = 1e-07,
> tol.opt = .Machine$double.eps^0.5, sparsedebug = FALSE)
> {
>     mt <- terms(formula, data = data)
>     mf <- lm(formula, data, na.action = na.action, method = "model.frame")
>     na.act <- attr(mf, "na.action")
>     if (!is.matrix.csr(weights))
>         cat("\nWarning: weights matrix not in sparse form\n")
>     switch(type, lag = if (!quiet)
>         cat("\nSpatial lag model\n"), mixed = if (!quiet)
>         cat("\nSpatial mixed autoregressive model\n"), stop("\nUnknown model
> type\n"))
>     if (!quiet)
>         cat("Jacobian calculated using weights matrix eigenvalues\n")
>     y <- model.response(mf, "numeric")
>     if (any(is.na(y))) stop("NAs in dependent variable")
>     x <- model.matrix(mt, mf)
>     if (any(is.na(x))) stop("NAs in independent variable")
>     if (nrow(x) != nrow(weights))
>         stop("Input data and weights have different dimensions")
>     n <- nrow(x)
>     m <- ncol(x)
> 
> When it reads the "Y" variable in the command:
> 
> "y <- model.response(mf, "numeric")"
> 
> The error it gives is:
> 
> "Error in model.response(mf, "numeric") : No direct or inherited method
> for function "model.response" for this call"
> 
> The problem is puzzling me because it is not something I encountered when I
> was running the same code in 1.9.0, but is causing problems in 2.0.1
> 
> Thanks, and any comments on debugging the error are welcome. 
> 
> Jim
> 
> Well I AM missing the back of my head.you COULD cut me a little slack!
> -Homer Simpson
> 

Jim,

The following works for me on R-2.0.1 on Win2000:

# example from ?lm
ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14)
trt <- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69)
group <- gl(2,10,20, labels=c("Ctl","Trt"))
weight <- c(ctl, trt)
lm.D9 <- lm(weight ~ group, method = "model.frame")
y <- model.response(lm.D9, "numeric")

HTH,

--sundar




More information about the R-help mailing list