Error using two natural splines in one formula

182 views
Skip to first unread message

rmip...@gmail.com

unread,
May 17, 2021, 10:50:28 AM5/17/21
to R-inla discussion group
Hi all,

Is there a way around a fault I'm getting when using two natural splines, via the ns function. Here's a toy example:

require(splines) ; require(INLA)
set.seed(12344)
x=rnorm(100)
y=rnorm(100)
z=rnorm(100)
data=data.frame(x=x,y=y,z=z)
fml = y ~ ns(x) + ns(z)
mod = inla(formula = fml,data=data)

When this runs, I get:

 *** Key [1] is used twice and that is not allowed.
 *** A typical example where this happens is: y ~ x + f(x)
 *** Change this formula into: y ~ x + f(x2)
 *** where you define x2=x

it seems to be something to do with the way that the subset of each spline is fed into the INLA formula, but am currently unsure how to fix it.

Any help would be very welcome.

Thanks a lot.

Robbie

Helpdesk

unread,
May 17, 2021, 10:52:46 AM5/17/21
to rmip...@gmail.com, R-inla discussion group

INLA does not us 'ns', but its own version of ``splines'', see
inla.doc("rw2")
> --
> You received this message because you are subscribed to the Google
> Groups "R-inla discussion group" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to r-inla-discussion...@googlegroups.com.
> To view this discussion on the web, visit
> https://groups.google.com/d/msgid/r-inla-discussion-group/b3884f4b-6e95-40ec-a99b-ebf36e6eb66an%40googlegroups.com
> .

--
Håvard Rue
he...@r-inla.org

rmip...@gmail.com

unread,
May 17, 2021, 12:30:49 PM5/17/21
to R-inla discussion group
Thanks so are rw2 and splines equivalent? 

INLA help

unread,
May 17, 2021, 12:56:34 PM5/17/21
to R-inla discussion group, rmip...@gmail.com
Read chapter 3 in the GMRF book 

Haavard Rue
HelpDesk 
help@r-inla. org

Finn Lindgren

unread,
May 17, 2021, 12:59:59 PM5/17/21
to rmip...@gmail.com, R-inla discussion group
Hi,
frequentist use of splines and Bayesian latent Gaussian models are never exactly equivalent since one refers to a maximum likelihood estimator and the other refers to a stochastic process model. However, ordinary cubic spline estimates are "equivalent" to the rw2 process model in the sense that for a rw2 process observed with additive independent gaussian noise, the posterior mode is the same the minimiser of a least squares problem with a cubic spline penalty, since the cubic spline minimises the same energy functional; the integral of the square of the second order derivative.
Finn



--
Finn Lindgren
email: finn.l...@gmail.com

rmip...@gmail.com

unread,
May 17, 2021, 2:58:47 PM5/17/21
to R-inla discussion group
Thanks that's really useful!
Reply all
Reply to author
Forward
0 new messages