Random walk in ulam
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 15/100
Research direction
The error comes from get_dist_template while ulam parses the alist model, so the problem is the loop-based random walk written inside the model block, not the data. Start by running the minimal example to reproduce the error, then check how ulam handles for loops and indexed assignments in its model parser. Done means the random-walk model compiles and samples, or the maintainer confirms the supported pattern.
Written by the indexing model from the issue text.
Description
I have been trying to implement a random walk in ulam. I'd be interested in how to do this in general after reading discussions such as this and this on how to build random walks in Stan and its other R interfaces such as brms.
Here is a MRE for a specific case trying to model the decay parameter k of the exponential decay function $f(x)=ae^{-kx}$ as a function of x using random walk:
# generate data
set.seed(10)
x <- 1:250
r <- rnorm(x, mean = 0, sd = sqrt(x^-1.5))
y <- 2 * exp(-0.04 * x) + r
require(tidyverse)
df <- tibble(x = x, y = y)
ggplot(df, aes(x, y)) +
geom_point() +
theme_minimal()
# prepare data for ulam
l <- as.list(df)
l$N <- length(l$x)
# run model
require(rethinking)
rw.mod <- ulam(
alist(
y ~ dnorm(mean = mu, sd = sigma),
mu <- a * exp(-k * x),
k <- 0.04,
for (i in 2:N) {
k[i] <- k[i - 1] + r
},
r ~ dnorm(mean = 0, sd = tau),
a ~ dlnorm(meanlog = log(2), sdlog = 0.5),
c(sigma, tau) ~ dexp(rate = 1)
), data = l, chains = 8, cores = parallel::detectCores(), iter = 1e4
)
This yields the following error: Error in get_dist_template(the_dist[1]) : No template for distribution ':'
I also tried specifying the vector 2:N in the for loop as seq(from = 2, to = N, by = 1), in which case I get the same error: Error in get_dist_template(the_dist[1]) : No template for distribution 'seq'
Any solutions or pointers would be greatly appreciated!
- Dominant language
- R
- Stars
- 2.4k
- Forks
- 632
- PR merge metrics
- No merged PRs in 30d
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from rmcelreath/rethinking
-
Typo: p.381Open
Difficulty 1/5 Under an hour Newbie friendliness 95/100
rmcelreath/rethinking#482 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
rmcelreath/rethinking#476 ·
-
Typo: p.302Open
Difficulty 1/5 Under an hour Newbie friendliness 88/100
rmcelreath/rethinking#475 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 62/100
rmcelreath/rethinking#474 ·
-
Comma splice: p.557Open
Difficulty 1/5 Under an hour Newbie friendliness 90/100
rmcelreath/rethinking#471 ·
All issues in rmcelreath/rethinking
Similar issues
-
1.7
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
pharmaverse/admiral#3235 ·
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
SticsRPacks/CroPlotR#185 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Maintainers usually reply within 1 day