使用R INLA超参数来实现θ和θ函数

时间:2018-01-03 19:09:44

标签: r

R-INLA模型超参数具有to.thetafrom.theta函数,这些函数似乎用于在不同参数之间进行转换。使用这些转换函数会很方便,但是如何使用它们呢?

ar1

的示例

来自ar1文档(http://www.math.ntnu.no/inla/r-inla.org/doc/latent/ar1.pdf):

  

参数rho表示为theta_2 = log((1 + rho)/(1-rho))

并进一步向下hypertheta2我们有to.theta 'function(x) log((1+x)/(1-x))'。如果我们可以使用它在rho和theta_2之间进行转换,那将是很好的。

让我们尝试使用示例

library(INLA)
# Example from ar1 documentation (http://www.math.ntnu.no/inla/r-inla.org/doc/latent/ar1.pdf)

#simulate data
n = 100
rho = 0.8
prec = 10
## note that the marginal precision would be
marg.prec = prec * (1-rho^2)
E=sample(c(5,4,10,12),size=n,replace=T)
eta = as.vector(arima.sim(list(order = c(1,0,0), ar = rho), n = n,sd=sqrt(1/prec)))
y=rpois(n,E*exp(eta))
data = list(y=y, z=1:n, E=E)
## fit the model
formula = y~f(z,model="ar1")
result = inla(formula,family="poisson", data = data, E=E)

运行正常。 我们可以像这样使用to.theta吗?

formula.to.theta = y~f(z,model="ar1", 
                       hyper = list(rho = list(initial = to.theta(0.25))))
result = inla(formula.to.theta,family="poisson", data = data, E=E)
# Error in to.theta(0.25) : could not find function "to.theta" 

所以我们不能那样使用它。还有另一种指定formula.to.theta的方法吗?

1 个答案:

答案 0 :(得分:1)

很确定你的问题的答案是"没有"。文档说,并不是包中有这些名称的函数,而是hyper超参数元素将具有文档中给出的值的那些名称的函数。没有理由认为在formula.之后粘贴这些名称会产生有意义的功能。以下是如何在from.theta函数的特定调用环境中检查f的值:

library(INLA)
eval( f(z, model = "ar1") )$hyper$theta3$from.theta
===== result ========
function (x) 
x
<environment: 0x7fdda6214040>
attr(,"inla.read.only")
[1] TRUE

f(,&#34; ar1&#34;)的结果实际上有三个theta,每个都有一个to和from函数。您可能正在尝试更改hyper$thetax$param值不attr(,"inla.read.only")的{​​{1}}。

执行此操作可能会提供更多信息:

TRUE