[R] "model.response" error
Roger Bivand
Roger.Bivand at nhh.no
Wed Jan 12 18:41:06 CET 2005
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).
I don't think it's the R versions, rather the SparseM versions. I think
what is happening is the SparseM generic for "model.response" is being
picked up. In the current NAMESPACE file in the spdep package I now have:
importFrom(stats, model.matrix, model.response)
but I'm not sure that your function is in a package. You will probably
need to say that both model.response and model.matrix are from stats, at
least this should give you a lead.
Best wishes,
Roger
>
> <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
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>
--
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Breiviksveien 40, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 93 93
e-mail: Roger.Bivand at nhh.no
More information about the R-help
mailing list