[R] "model.response" error
Prof Brian Ripley
ripley at stats.ox.ac.uk
Wed Jan 12 18:34:58 CET 2005
You have some package in use which defines an S4 method for
model.response, most likely SparseM. You didn't say that, but therein
lies the problem. It's hard for us to guess why it is failing to find
its default method.
Incidentally,
mf <- lm(formula, data, na.action = na.action, method = "model.frame")
is a roundabout way to do
mf <- model.frame(formula, data, na.action = na.action)
On Wed, 12 Jan 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
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-help
mailing list