Comments (4)
Some bug specific to binomial outcomes perhaps? I may not have time to figure it out today, but will make an issue of it.
from rethinking.
Quick assessment, two things going on:
(1) not enough samples in model, so subscript error. this is a bug, but goes away if you sample more chains.
(2) the logit(prob) <- p line generates only a single value, so postcheck generates only a single prediction. can hack it to work by doing something like:
logit(prob) <- p + 0*density
but will need to add special logic to somehow deal with this kind of thing in general.
from rethinking.
I have been thinking of replacing the old postcheck with Aki's PIT plots as default. But I need to make more time in my life to work through my dev notes.
from rethinking.
Huh - had not run across LOO-PIT yet. Damn this field keeps evolving. I had however, re-implemented Quantile Residual checks, much like in the DHARMa package.
quantile_residuals <- function(fit, n=1000){
# get y - from rethinking::postcheck
lik <- (fit@formula)[[1]]
outcome <- as.character(lik[[2]])
if (class(fit) == "ulam")
outcome <- undot(outcome)
y <- fit@data[[outcome]]
# get the ecdfs
s <- sim(fit, n = n)
dists <- apply(s, 1, ecdf)
#get the quantile residuals
quant_res <- numeric(ncol(s))
for(i in 1:length(y)){
quant_res[i] <- dists[[i]](y[i])
}
return(quant_res)
}
This is nice because then you can make QQ plots like so:
data(cars)
flist <- alist(
dist ~ dnorm( mu , sigma ) ,
mu <- a+b*speed ,
c(a,b) ~ dnorm(0,1) ,
sigma ~ dexp(1)
)
fit <- quap( flist , start=list(a=40,b=0.1,sigma=20) , data=cars )
quantile_residuals(fit) |>
gap::qqunif(logscale=FALSE)
But - I'm guessing this will have similar issues for binomial models?
I'd imagine calculating LOO-PITs must be somewhat similar? Need to read, though.....
And, I suppose if you want to make a hot plot like the ones I now see in bayesplot - well, you could do it with quantil residuals as well
# plot against unif dists
get_rep_unifs <- function(samples, n = 100){
data.frame(
id = sort(rep(1:samples, n)),
unif = runif(samples*n)
)
}
library(ggplot2)
bayes_qr_plot <- function(fit, n = 1000, n_unif = 100, ...){
q <- quantile_residuals(fit)
get_rep_unifs(length(q), n_unif) |>
ggplot(aes(x = unif, group = id)) +
geom_density(color = alpha("black", 0.3), ...) +
geom_density(data = data.frame(unif = q, id = 1),
linewidth = 3, ...)
}
bayes_qr_plot(fit)
Which I suppose could serve the basis of a plotting function. Yes, yes, I know, I prefer ggplot2. I'm very tidy. Or try to be. I'm sure this could be done in base, but, wow, my base brain is.... stale.
from rethinking.
Related Issues (20)
- How to construct a spline model using ulam() HOT 4
- cannot install rethinking HOT 1
- Error in link(), R code 4.67 HOT 1
- Poisson response imputation compilation error
- Random Effect in Zero-Inflated Model
- Rethink package is NOT getting installed HOT 8
- Sampling issue for the Cat Adoptions Survival model.
- Random walk in ulam HOT 2
- problem in precis command
- Can multiple outcomes be regressed on the same linear model?
- ulam fits missing @stanfit slot? HOT 2
- WAIC not computing from ulam() model, even with log_lik = TRUE HOT 4
- Problem installing cmdstanr HOT 1
- errata 2nd Edition page 130
- log_lik fails with matrices in models fit by ulam HOT 6
- Where is sim_globe, and the rest of the code shown in the videos? HOT 2
- Panda_nuts Nut-Cracking Frequency? HOT 6
- The garden of forking data - 2 blue from 1? HOT 3
- quap allows incorrect(?) definition with categorical variable HOT 1
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 rethinking.