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
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
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
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