Plot with residuals in mgcv
fit29<- gam(IV~s(G3)+s(V3)+factor(AAR)+s(D3)+s(RUTE,bs="re"),data=subsf,gamma=1.4,method ="ML") plot(fit29,residuals=T) Error in X[, first:last] %*% object$coefficients[first:last] : non-conformable arguments
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
-----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Peter Ehlers Sent: Wednesday, November 28, 2012 12:17 PM To: silje sk?r Cc: r-help at r-project.org Subject: Re: [R] Plot with residuals in mgcv On 2012-11-28 05:02, silje sk?r wrote:
Hi, I am using the mgcv package (version 1.7-22.) running the model works fine, but when I want to have a plot with residuals I get an error. fit29<-
gam(IV~s(G3)+s(V3)+factor(AAR)+s(D3)+s(RUTE,bs="re"),data=subsf,gamma=1.4,method ="ML")
plot(fit29,residuals=T) Error in X[, first:last] %*% object$coefficients[first:last] : non-conformable arguments does some one know what this error means? the subsf matrix is 35x27. Silje
Well, the error means that the matrix X[, first:last] and the vector object$coefficients[first:last] don't have 'matching' dimensions. I don't see why, but since the 'residuals' argument to plot.gam() can be an array _of the correct length_ (see ?plot.gam), it just might be that you have an object called 'T' hanging around, in which case using 'T' in place of 'TRUE' is a bad idea. Actually, it's _always_ a bad idea. Peter Ehlers
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.