[R] Inscrutable error message in mgcv: 1> prediction = predict(MI, se.fit=TRUE, newdata=rhc), Error in if (object$inter) X[[i]] <- PredictMat(object$margin[[i]], dat, : , argument is of length zero
Simon Wood
s.wood at bath.ac.uk
Tue Oct 29 18:19:24 CET 2013
Sorry, this relates to ?"mgcv-FAQ" number 5, unfortunately. 'ti' terms
were introduced as a much better and cleaner way of allowing smooth main
effects and interactions where the interactions are based on 'te' terms:
this required some re-engineering of the tensor product smooth objects
(the offending 'iter' element of the smooth is how 'ti' terms are
distinguished from normal 'te' terms internally). I'm afraid this won't
work in the current mgcv without re-fitting the original model.
Simon
On 26/10/13 10:33, Andrew Crane-Droesch wrote:
> Dear List,
>
> I am trying to reproduce a figure that I made for an analysis that I did
> a few months ago. Between when I first made the figure and now, I've
> upgraded to R 3.0.2 and upgraded my operating system (ubuntu 13.04). My
> codebase, which once works, is throwing an error when I try to use
> predict.gam on a model object that I saved:
>
> 1> prediction = predict(MI,se.fit=TRUE,newdata=rhc)
> Error in if (object$inter) X[[i]] <- PredictMat(object$margin[[i]], dat, :
> argument is of length zero
>
> traceback() gives me the following:
>
> 1> traceback()
> 6: Predict.matrix.tensor.smooth(object, dk$data)
> 5: Predict.matrix(object, dk$data)
> 4: Predict.matrix3(object, data)
> 3: PredictMat(object$smooth[[k]], data)
> 2: predict.gam(MI, se.fit = TRUE, newdata = rhc)
> 1: predict(MI, se.fit = TRUE, newdata = rhc)
>
> the final function being called looks like this:
>
> 1> Predict.matrix.tensor.smooth
> function (object, data)
> {
> m <- length(object$margin)
> X <- list()
> for (i in 1:m) {
> term <- object$margin[[i]]$term
> dat <- list()
> for (j in 1:length(term)) dat[[term[j]]] <- data[[term[j]]]
> if (object$inter)
> X[[i]] <- PredictMat(object$margin[[i]], dat, n =
> length(dat[[1]]))
> else X[[i]] <- Predict.matrix(object$margin[[i]], dat)
> }
> mxp <- length(object$XP)
> if (mxp > 0)
> for (i in 1:mxp) if (!is.null(object$XP[[i]]))
> X[[i]] <- X[[i]] %*% object$XP[[i]]
> T <- tensor.prod.model.matrix(X)
> T
> }
>
> Unfortunately, I can't say that I understand how that function is
> working, beyond that it takes a fitted model object and makes a piece of
> the model matrix.
>
> Any ideas about what this could stem from? Where to start looking to
> fix it? I could probably do the entire analysis from scratch, but it is
> quite complex and I'd prefer to save the time.
>
> Apologies for non-reproducible code -- the data is big and the script is
> long.
>
> Thanks for any assistance,
> Andrew
>
> ______________________________________________
> 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.
--
Simon Wood, Mathematical Science, University of Bath BA2 7AY UK
+44 (0)1225 386603 http://people.bath.ac.uk/sw283
More information about the R-help
mailing list