-
Notifications
You must be signed in to change notification settings - Fork 11
Open
Description
Hi,
I want to have a Gaussian variable affecting a categorical variable. I tried this which seems to work
C <- rnorm(3,0,2) # or even rnorm(1,0,2)
rcat.b1(250, softmax(C * c(0.5, 0.25, 0.25)))
But running the below only gets me category 4, while there are only three categories?
logsumexp <- function (x) {
y = max(x)
y + log(sum(exp(x - y)))
}
softmax <- function (x) {
exp(x - logsumexp(x))
}
D <- DAG.empty()
N <- 250
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)))
Dset <- set.DAG(D, vecfun = c("softmax"))
d <- sim(Dset, n = N)
r$> head(d)
ID C BA
1 1 -1.3004380 4
2 2 3.4434901 4
3 3 -1.7159391 4
4 4 3.7295937 4
5 5 -1.7967269 4
6 6 -0.8985413 4
Have I misunderstood something? :)
Metadata
Metadata
Assignees
Labels
No labels