An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20121128/88a902da/attachment.pl>
Plot with residuals in mgcv
4 messages · silje skår, Peter Ehlers, William Dunlap +1 more
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
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.
Hi Silje, Thanks for this. I guess RUTE is a numeric variable in this model and hence only has one associated random coefficient? This then causes a problem when calling predict.gam as part of processing 'residuals=T'. I've fixed the problem for the next release, but did you really want a single random slope for RUTE, or should it really have been declared as a factor variable? btw gamma doesn't do anything with ML and REML smoothness selection (it's only used in prediction error criteria smoothness selection to increase the penalization per effective degrees of freedom). best, Simon
On 28/11/12 13: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 [[alternative HTML version deleted]]
______________________________________________ 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.