[R-sig-Geo] Predict leads to 'non-conformable arguments'

Roger Bivand Roger.Bivand at nhh.no
Wed Mar 14 21:42:44 CET 2012


On Wed, 14 Mar 2012, Roger Bivand wrote:

> On Tue, 13 Mar 2012, Smit, M.J. wrote:
>
>> Dear list,
>> 
>> I'm trying to do a scenario analysis by changing a few values in the 
>> dataset, and running 'predict' from spdep both before and after. However, I 
>> get 'non-comformable arguments', even when I just add the old dataset as 
>> 'newdata='. What is happening?
>
> Please do provide reproducible cases. This isn't, as you neither use built in 
> data, nor a link to your own data.
>
> Also always name arguments to functions as this disambiguates the calls, and 
> avoids helpers having to look the arguments up.

This may or may not be the case in question:

library(spdep)
data(boston)
gp2 <- lagsarlm(log(CMEDV) ~ CRIM + ZN + INDUS + CHAS + I(NOX^2) + I(RM^2)
  +  AGE + log(DIS) + log(RAD) + TAX + PTRATIO + B + log(LSTAT) + TOWN,
  data=boston.c, nb2listw(boston.soi), method="eigen", tol.solve=1e-12)
p2 <- predict(gp2, newdata=boston.c, listw=nb2listw(boston.soi))
# Error in X %*% B : non-conformable arguments
summary(gp2) # NA coefficients

because predict() assumed that the user checked the model fit for 
aliasing. A fix for predict() will be in the next spdep, but users really 
should check that fitted coefficients are not aliased by colinearity.

Roger


>
> Roger
>
>> 
>> My lagsarlm runs fine; so does the first prediction ("pred1"). It is the 
>> second one that fails.
>> A sample of my code:
>> dat2 <- data.frame(NUTS_ID,COUNTRY,SPEND,<and 20 other variables> )
>> wgdist2 <- mat2listw(matgdist,dat2$NUTS_ID)
>> durbland <- lagsarlm(form_land,dat2,wgdist2,type="mixed")
>> summary(durbland)
>> pred1 <- predict(durbland,NULL,wgdist2,zero.policy=TRUE)
>> pred2 <- predict(durbland,dat2,wgdist2,zero.policy=TRUE) # Note this fails, 
>> although the data is identical.
>> 
>> ... and the last command always gets me
>> Error in X %*% B : non-conformable arguments
>> 
>> even before I get to executing
>> dat2$SPEND[dat2$COUNTRY=="PL"] <- dat2$SPEND[dat2$COUNTRY=="PL"]*2
>> 
>> Best regards,
>> Martijn
>> 
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo at r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>> 
>
>

-- 
Roger Bivand
Department of Economics, NHH Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no



More information about the R-sig-Geo mailing list