Skip to content
Prev 312298 / 398506 Next

Plot with residuals in mgcv

Those errors often come from omitting the drop=FALSE argument to [ when subscripting
a matrix.  It looks like that is the problem here (I am still using R 2-2.15.1 and mgcv 1.7.18):

  > fit <- gam(mpg ~ s(wt, bs="re") + am, data=mtcars)
  > plot(fit, residuals=TRUE)
  Error in X[, first:last] %*% object$coefficients[first:last] : 
    non-conformable arguments

  Enter a frame number, or 0 to exit   

  1: plot(fit, residuals = TRUE)
  2: plot.gam(fit, residuals = TRUE)
  3: predict(x, type = "terms")
  4: predict.gam(x, type = "terms")

  Selection: 4
  Called from: predict.gam(x, type = "terms")
  Browse[1]> first:last # length 1 result means first==last
  [1] 3
  Browse[1]> try(X[, first:last] %*% object$coefficients[first:last])
  Error in X[, first:last] %*% object$coefficients[first:last] : 
    non-conformable arguments
  Browse[1]> try(X[, first:last, drop=FALSE] %*% object$coefficients[first:last])
              [,1]
   [1,] -13.720247
   [2,] -15.055614
   [3,] -12.149226
   [4,] -16.836104
   [5,] -18.014370
   ...
   [32,] -14.558125

If this is still the problem in the latest version of mgcv you should write
to mgcv's maintainer about the problem.
  > maintainer("mgcv")
  [1] "Simon Wood <simon.wood at r-project.org>"

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com