-
Notifications
You must be signed in to change notification settings - Fork 11
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
Gaussian var affecting categorical var #19
Comments
I now use Where
|
where do you get rbeta_mean? Can you include the R package or definition. Also can you include the values of b_H, b_BA, and b_C? |
The problem with your softmax implementation is that it does not handle matrix input correctly. Compare the results between rethinking softmax and your softmax: softmax=rethinking::softmax
logsumexp <- function (x) {
y = max(x)
y + log(sum(exp(x - y)))
}
softmax2 <- function (x) {
exp(x - logsumexp(x))
}
set.seed(123)
test=matrix(rnorm(21,0,1),ncol=3)
test
softmax(test)
softmax2(test)
and I think the problem is coming from logsumexp(test)
|
https://github.com/sims1253/bayesim is where N <- 250 # Sample size
# Set beta effects
b_H <- 0.3
b_BA <- 0.2
b_C <- 0.5
D <- DAG.empty()
D <- D +
# Confounder with Gaussian distribution
node("C",
distr = "rnorm",
mean = 0,
sd = 2) +
# Set BA to categorical (c=3).
# Make sure it starts at 1, to ensure sane priors later.
# Let C be a causal effect on BA.
node("BA",
distr = "rcat.b1",
probs = softmax(C * c(0.5, 0.25, 0.25))) +
# Set H to categorical (c=3).
# Let BA be a causal effect on H.
node("H",
distr = "rcat.b1",
probs = (BA == 1) * c(0.7, 0.1, 0.2) + (BA == 2) * c(0.2, 0.1, 0.7) + (BA == 3) * c(0.2, 0.1, 0.7)) +
# Generate Beta(mu, phi) with H, BA, and C.
# Note: We use rbeta_mean() which is a mean parameterization of Beta.
node("P",
distr = "rbeta_mean",
phi = 4,
mu = inv_logit(b_H * H + b_BA * BA + b_C * C))
# Need to use inv_logit() since mu in Beta needs it when modelling
Dset <- set.DAG(D, vecfun = c("inv_logit", "softmax"))
# Gen N samples
d <- simcausal::sim(Dset, n = N)
d$P[d$P == 1] <- 0.99999999 # nudge iff 1 |
Hi,
I want to have a Gaussian variable affecting a categorical variable. I tried this which seems to work
But running the below only gets me category 4, while there are only three categories?
Have I misunderstood something? :)
The text was updated successfully, but these errors were encountered: