Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

i meet bollow error todaycan you help me #102

Open
tianjinwolaile opened this issue Oct 28, 2024 · 2 comments
Open

i meet bollow error todaycan you help me #102

tianjinwolaile opened this issue Oct 28, 2024 · 2 comments

Comments

@tianjinwolaile
Copy link

library(INLA)
n <- 10
locations <- data.frame(x = runif(n), y = runif(n))
values <- rnorm(n)
w <- matrix(0, n, n)
for (i in 1:n) {
for (j in 1:n) {
dist <- sqrt((locations$x[i] - locations$x[j])^2 + (locations$y[i] - locations$y[j])^2)
if (dist < 0.2) {
w[i, j] <- 1
}
}
}

formula <- values ~1+f(1,model = "bym",graph = w)
undebug(INLA:::inla.interpret.formula)
result <- inla(formula, data = locations, family = "gaussian")
print(result)
image
is my model have wrong?think you!

@finnlindgren
Copy link
Collaborator

finnlindgren commented Oct 28, 2024

Your component specification is wrong. You likely need this:

library(INLA)
n <- 10
locations <- data.frame(index = seq_len(n), x = runif(n), y = runif(n))
values <- rnorm(n)
w <- matrix(0, n, n)
for (i in 1:n) {
  for (j in 1:n) {
    dist <- sqrt((locations$x[i] - locations$x[j])^2 + (locations$y[i] - locations$y[j])^2)
    if (dist < 0.2) {
      w[i, j] <- 1
    }
  }
}

formula <- values ~1+f(index,model = "bym",graph = w)
result <- inla(formula, data = locations, family = "gaussian")
print(result)

@tianjinwolaile
Copy link
Author

@finnlindgren ,it work,thank you.but i find other problem,my data does't fit gaussian,so i chose poisson,
library(INLA)

set.seed(123)
n <- 100
lambda <- 3
y <- rpois(n, lambda)
data <- data.frame(y = y)

formula <- y ~ 1

result <- inla(formula, data = data, family = "poisson",
control.family = list(hyper = list(prec = list(prior = "gamma", param = c(1, 0.1)))))

i meet those error,the ,
control.family = list(hyper = list(prec = list(prior = "gamma", param = c(1, 0.1))))is shoud be deleted?thank you.i just want set a hyper
Error in inla.core.safe(formula = formula, family = family, contrasts = contrasts, :
Model poisson [ likelihood ], has none hyperparameters, but 'hyper' is list(prec = list(prior = "gamma", param = c(0.5, 0.1)))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants