// covariance matrix Sigma <- sigma_sq * inverse(D - p * A); for (i in 1:N) for (j in 1:i) Sigma[i,j] <- Sigma[j,i]; chol_Sigma <- cholesky_decompose(Sigma);// CAR model beta1 ~ multi_normal_cholesky(zeros, chol_Sigma);The Cholesky version should be much faster, either called directly
or implemented directly with lp__.
So you could probably just symmetrize A if
that's where the issue is.
There are also two things we could do internally to
correct for this. First, we could increase the error
tolerance -- your inputs look like they're identical to
6 decimal places.
Thanks Ben! Any idea why the multi_normal_prec() version doesn't seem to work? It's not in the manual but I assumed I should just pass in the precision matrix i.e. the inverse of the covariance matrix. But it predicts all zeroes and gives a much higher lp than the covariance parameterization (as well as being a bit slower, probably due to the checks for symmetry etc) .
--
You received this message because you are subscribed to a topic in the Google Groups "stan users mailing list" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/stan-users/S8dhFpn0Lg8/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to stan-users+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Any idea why the precision's not working for Kyle? It
looks like all the tests are in place for values and
autodiff.
real<lower=1e-5> tau; // precision of CAR
real<lower=0,upper=1> p;// strength of spatial correlation
> g_lp <- stan(
+ file = 'lp_method.stan',
+ data = dat,
+ init = init,
+ chains = 1, test_grad = TRUE)
TRANSLATING MODEL 'lp_method' FROM Stan CODE TO C++ CODE NOW.
COMPILING THE C++ CODE FOR MODEL 'lp_method' NOW.
TESTING GRADIENT FOR MODEL 'lp_method' NOW (CHAIN 1).
TEST GRADIENT MODE
Log probability=683.794
param idx value model finite diff error
0 0 -0.2 -0.2 1.58657e-07
...
58 -1.00001e-05 56.4989 56.4989 -9.02741e-09
59 0 -1.28883 -1.28883 -2.64132e-08
> g_mnp <- stan(
+ file = 'multi_normal_prec.stan',
+ data = dat,
+ init = init,
+ chains = 1,
+ test_grad = TRUE)
TRANSLATING MODEL 'multi_normal_prec' FROM Stan CODE TO C++ CODE NOW.
COMPILING THE C++ CODE FOR MODEL 'multi_normal_prec' NOW.
TESTING GRADIENT FOR MODEL 'multi_normal_prec' NOW (CHAIN 1).
TEST GRADIENT MODE
Log probability=721.016
param idx value model finite diff error
0 0 -0.2 -0.2 1.58657e-07
...
58 -1.00001e-05 112.498 112.498 -1.68086e-08
59 0 -2.57767 -2.57767 4.017e-09
> log_prob(g_lp, pars = unlist(init))
[1] 739.4773
> log_prob(g_mnp, pars = unlist(init))
[1] 831.9454
If we do it in doubles and keep the constants, we get> log_prob(g_lp, pars = unlist(init))
[1] 739.4773
> log_prob(g_mnp, pars = unlist(init))
[1] 831.9454
Kyle, do you know which is the correct log posterior for this data-generating process?
But using the code Ben helped with a couple weeks ago to use lp__ directly is even faster, about 50% faster than multi_normal_prec(). So I'm guessing there's some additional overhead in the multi_normal_prec() function that slows it down a bit.
lp__ <- lp__ - 0.5 / (sigma * sigma) * (beta1' * D * beta1 - p * (beta1' * A * beta1));lp__ <- lp__ - 0.5 * N * log(sigma * sigma) + 0.5 * log(determinant(D - p * A));
Tau <- (tau * tau) * (D - p * A);
beta1 ~ multi_normal_prec(zeros, Tau);
Hi all,
I've been bouncing back and forth on all things related to the spatial CAR implementation in STAN.
For other people in a similar situation, here's a new tidbit from my scavenging.
To implement Kyle's examples,
a slight modification in data section of the stan file needs to be made
wrong:
vector[N] O;
right:
int O[N];
I could be completely wrong, as this is my first dive into STAN, but it's motivated from reading
https://groups.google.com/forum/#!msg/stan-dev/vNx8FyKcsLs/b7ft0lyZWXoJ
Mike
To unsubscribe from this topic, visit https://groups.google.com/d/topic/stan-users/S8dhFpn0Lg8/unsubscribe.--
You received this message because you are subscribed to a topic in the Google Groups "stan users mailing list" group.
To unsubscribe from this group and all its topics, send an email to stan-users+...@googlegroups.com.
Hi all,
I hope this isn't regarded as redundant spam.
I've started a seperate thread trying to extend the spatial car model (single random effect) into the bym convolution model ( car random effect and normal random effect) as well as scaling up the model to 480 spatial neighbors (instead of the 50 or so here).
https://groups.google.com/forum/#!searchin/stan-users/spatial|sort:date/stan-users/M7T7EIlyhoo/jli3CRobjeIJ
Stan isn't able to handle it and I was wondering if people in this thread would have some knowledge as to what's going on.
--To unsubscribe from this topic, visit https://groups.google.com/d/topic/stan-users/S8dhFpn0Lg8/unsubscribe.
You received this message because you are subscribed to a topic in the Google Groups "stan users mailing list" group.
To unsubscribe from this group and all its topics, send an email to stan-users+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.