Comments (8)
For this one, we need to use a custom family. We can use the Stan's normal_lpdf and normal_rng if we replace sigma with 0.001.
This code should work. It's based off the brms vignette on custom families.
d <-
tibble(species = c("afarensis", "africanus", "habilis", "boisei", "rudolfensis", "ergaster", "sapiens"),
brain = c(438, 452, 612, 521, 752, 871, 1350),
mass = c(37.0, 35.5, 34.5, 41.5, 55.5, 61.0, 53.5)) %>%
mutate(mass_std = (mass - mean(mass)) / sd(mass),
brain_std = brain / max(brain))
custom_normal <- custom_family(
"custom_normal", dpars = "mu",
links = "identity",
type = "real"
)
stan_funs <- "real custom_normal_lpdf(real y, real mu) {
return normal_lpdf(y | mu, 0.001);
}
real custom_normal_rng(real mu) {
return normal_rng(mu, 0.001);
}
"
stanvars <- stanvar(scode = stan_funs, block = "functions")
m7.6 <- brm(data = d,
family = custom_normal,
formula = brain_std ~ 1 + poly(mass_std, 6),
prior = c(prior(normal(0.5, 1), class = Intercept),
prior(normal(0, 10), class = b)),
stanvars = stanvars,
chains = 4,
cores = 4,
iter = 2000,
warmup = 1000)
expose_functions(m7.6, vectorize = TRUE)
posterior_epred_custom_normal <- function(prep) {
mu <- prep$dpars$mu
mu
}
mass_std <- seq(-1.5, 1.5, length.out = 1000)
fits <- fitted(m7.6, newdata = list(mass_std = mass_std))
fits <- data.frame(fits,
mass_std = mass_std)
ggplot() + geom_line(data = fits,
mapping = aes(x = mass_std,
y = Estimate),
colour = "blue") +
geom_ribbon(data = fits, mapping = aes(x = mass_std,
ymin = Q2.5,
ymax = Q97.5),
fill = "blue",
alpha = 0.5) +
geom_point(d, mapping = aes(x = mass_std,
y = brain_std),
colour = "blue") +
theme_minimal()
I hope that helps!
Steve
from statistical_rethinking_with_brms_ggplot2_and_the_tidyverse_2_ed.
Dude, you're on fire. So I can acknowledge you in the thank you section of the next update, what's your author name?
from statistical_rethinking_with_brms_ggplot2_and_the_tidyverse_2_ed.
My name is Stephen Wild. I'm happy to contribute a little. I found your first edition helpful when I started learning bayes and Stan, so I figured a little help is the least I can do. If all goes well, I may (or may not, most likely) succeed with the ODE models.
Steve
from statistical_rethinking_with_brms_ggplot2_and_the_tidyverse_2_ed.
Right on. If you can get those ODE's, it'd be a major help.
from statistical_rethinking_with_brms_ggplot2_and_the_tidyverse_2_ed.
The current implementation lives here.
from statistical_rethinking_with_brms_ggplot2_and_the_tidyverse_2_ed.
That's awesome! The ODE problem is interesting, because we're actually dealing with two issues: ODEs and a state-space model (at least for lynx-hare). This one's going to require some thinking.
from statistical_rethinking_with_brms_ggplot2_and_the_tidyverse_2_ed.
I'd also be interested in an example or two of a much simpler ODE, something easier for us novices to grapple with.
from statistical_rethinking_with_brms_ggplot2_and_the_tidyverse_2_ed.
I agree. My knowledge of ODEs is limited to 2 things: 1) they exist, and 2) I couldn't solve one if my life depended on it.
from statistical_rethinking_with_brms_ggplot2_and_the_tidyverse_2_ed.
Related Issues (20)
- retraction whitehouseComplexSocietiesPrecede2019 HOT 2
- {posterior} HOT 1
- b11.11 HOT 1
- 4.4.3.1 posterior_samples deprecation HOT 2
- drop {urbnmapr} for {tigris} HOT 1
- Ch 5 DAGs
- Chapter 10.1.1: plot of shape and entropy HOT 2
- Section 12. 4 Figure 12.8 HOT 3
- Ch 6.3.1 sim_happiness function HOT 2
- residuals
- Quarto port and content update for 2023 lectures + beginning of 3rd edition HOT 1
- Section 4.4.3.4. Predictions for E{height} at a given weight HOT 2
- Section 4.4.3.5 Using `nesting` when doing posterior calculations HOT 7
- Please use `linewidth` instead.
- residuals and history
- social media
- 3.4 brms::fitted() results in "not an exported object from 'namespace:brms'" error HOT 7
- dplyr::lag()
- DAG on 15.2.1
- 4.3.6 tidyverse parallel for the transformed base R
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from statistical_rethinking_with_brms_ggplot2_and_the_tidyverse_2_ed.