R-INLA模型超参数具有to.theta和from.theta函数,这些函数似乎用于在不同参数化之间进行转换。使用这些转换函数是很方便的,但是如何使用呢?
使用ar1的示例
来自ar1文档(http://www.math.ntnu.no/inla/r-inla.org/doc/latent/ar1.pdf):
参数rho表示为theta_2 = log((1 +rho)/(1-Rho))
在hyper下面,theta2,我们有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吗?
发布于 2018-01-04 01:02:04
你问题的答案肯定是“不”。文档并不是说包中有这些名称的函数,而是hyper超参数元素将通过这些名称具有函数,这些名称与文档中给出的值相同。没有理由认为在formula.之后粘贴这些名称会产生一个有意义的函数。下面是如何检查from.theta在特定调用f-function的环境中的值:
library(INLA)
eval( f(z, model = "ar1") )$hyper$theta3$from.theta
===== result ========
function (x)
x
<environment: 0x7fdda6214040>
attr(,"inla.read.only")
[1] TRUEf(,"ar1")的结果实际上有三个theta的,每个函数都有一个to和from函数,您可能试图更改没有attr(,"inla.read.only")值TRUE的hyper$thetax$param值。
对您来说,执行以下操作可能会提供更多的信息:
eval( f(z, model = "ar1") )$hyperhttps://stackoverflow.com/questions/48083679
复制相似问题