R package "spartstat": how do you get standard errors for nonsmooth terms in the Poisson process model (function: ppm) when use.gam = TRUE?

In the R spatstat package (I am using the current version 1.31-0 ), there is the use.gam option. When you set it to true, you can include smooth terms in a linear predictor, just like with the mgcv R package. For instance,

 g <- ppm(nztrees, ~1+s(x,y), use.gam=TRUE) 

Now, if I need a confidence interval for interception, you can usually use summary or vcov , which works when you don't use gam , but fails when you use gam

 vcov(g) 

which gives an error message

 Error in model.frame.default(formula = fmla, data = list(.mpl.W = c(7.09716796875, :invalid type (list) for variable 's(x, y)' 

I know that this standard error approximation is not justified here when using gam , but it displays a warning message:

 In addition: Warning message: model was fitted by gam(); asymptotic variance calculation ignores this 

I am not worried about this - I am ready to justify using these standard errors for the purpose that I use them - I just want numbers and would like to avoid "write by myself" like that.

The error message I received above does not seem to depend on the dataset I use. I used the nztrees example here because I know that it is loaded using spatstat . He seems to be complaining about this variable, but the model clearly understands the syntax because it matches the model (and the predicted values โ€‹โ€‹for my own dataset look pretty good, so I know it's not just dumping garbage).

Does anyone have any tips or ideas? This is mistake? To my surprise, I could not find a discussion of this online. Any help or hints are welcome.

Edit: Although I finally answered my own question here, I will not accept my answer yet. Thus, if someone is interested and wants to make an effort to find a โ€œworkaroundโ€ for this, without waiting for the next spatstat release, I can award him a reward. Otherwise, I will simply accept my answer at the end of the period of generosity.

+6
source share
2 answers

I contacted one of the authors of the Adrian Baddeley package about this. He quickly answered and informed me that this is really a software bug, and, apparently, I am the first person I encountered. Fortunately, it took him only a short time to track down the problem and fix it. A fix will be included in the next release of sleepstat, 1.31-1.

Edit: An updated version of spatstat been released and no longer has this error:

 g <- ppm(nztrees, ~1+s(x,y), use.gam=TRUE) sqrt( vcov(g)[1,1] ) [1] 0.1150982 Warning message: model was fitted by gam(); asymptotic variance calculation ignores this 

See spartstat for other release notes. Thanks to everyone who read and participated in this thread!

+4
source

I am not sure that you can indicate the trend as you have, which may cause an error. It doesn't seem to make sense according to the documentation :

The default formula, ~1, indicates the model is stationary and no trend is to be fitted.

But instead, you can specify the model as follows:

 g <- ppm(nztrees, ~x+y, use.gam=TRUE) #Then to extract the coefficientss: >coef(g) (Intercept) xy -5.0346019490 0.0013582470 -0.0006416421 #And calculate their se: vc <- vcov(g) se <- sqrt(diag(vc)) > se (Intercept) xy 0.264854030 0.002244702 0.003609366 

Does this make sense / expected result? I know that package authors are very active on the r-sig-geo lsit mailing list, as they have helped me in the past. You can also submit your question to this mailing list, but you must include your question.

+1
source

All Articles