You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was working through your example code in example(sampler) and when I run out <- sampler(simu_dat,model_options0,mcmc_options0) for the first example, I get the following error: Error in log_p[t + 1] <- log_v[t + 1] - log_v[t] + log(b) + log_marginal(dat[i, : replacement has length zero. I was wondering if you have any insights on how to resolve this? Below is all the code I've run and sessionInfo
library(rewind)
example(sampler)
library(matrixStats)
library(ars) #adaptive rejection sampling
# color palette for heatmaps:
YlGnBu5 <- c('#ffffd9','#c7e9b4','#41b6c4','#225ea8','#081d58',"#092d94")
hmcols <- colorRampPalette(YlGnBu5)(256)
# simulate data:
L0 <- 100
options_sim0 <- list(N = 200, # sample size.
M = 3,
L = L0,
K = 8,
theta = rep(0.9,L0), # true positive rates.
psi = rep(0.1,L0), # false positive rates.
alpha1 = 1, # half of the people have the first machine.
frac = 0.2, # fraction of positive dimensions (L-2M) in Q.
#pop_frac = rep(1/K0,K0) # population prevalences.
pop_frac = c(rep(2,4),rep(1,4)) # population prevalences.
)
str(options_sim0)
image(simulate_data(options_sim0,SETSEED = TRUE)$datmat,col=hmcols)
simu <- simulate_data(options_sim0, SETSEED=TRUE)
str(simu)
simu_dat <- simu$datmat
str(simu_dat)
rle(simu$Z)
#
# visualize truth:
#
plot_truth(simu,options_sim0)
#
# specifying options:
#
# model options:
m_max0 <- 5
model_options0 <- list(
n = nrow(simu_dat),
t_max = 40,
m_max = m_max0,
b = 1, # Dirichlet hyperparameter; in the functions above,
# we used "b" - also can be called "gamma"!.
#Q = simu$Q,
a_theta = replicate(L0, c(9,1)),
a_psi = replicate(L0, c(1,9)),
#theta = options_sim0$theta,
#psi = options_sim0$psi,
alpha = 0.1,
frac = 0.2,
#p_both = rep(0.5,3),#,c(0.5,0.5^2,0.5^3,0.5^4,0.5^5)
#p0 = rep(0.5,m_max0), # <--- this seems to make a difference in convergence.
log_pk = "function(k) {log(0.1) + (k-1)*log(0.9)}"# Geometric(0.1).
#Prior for the number of components.
)
# pre-compute the log of coefficients in MFM:
model_options0$log_v<-mfm_coefficients(eval(parse(text=model_options0$log_pk)),#response probability/Bernoulli
model_options0$b, #Dirichelet hyperparameter
model_options0$n,#200, number of subjects
model_options0$t_max+1) #upper limit to compute the coefficient
# mcmc options:
mcmc_options0 <- list(
n_total = 200,
n_keep = 50,
n_split = 5, #??? number of splits
print_mod = 10,
constrained = TRUE, # <-- need to write a manual about when these options are okay.
block_update_H = TRUE,
block_update_Q = !TRUE,
ALL_IN_ONE_START =!TRUE, # <--- TRUE for putting all subjects in one cluster,
# FALSE by starting from a hierechical clustering
# (complete linkage) and cut
# to produce floor(t_max/4). Consider this as a warm start.
MORE_SPLIT = TRUE,
print_Q = TRUE,
init_frac = c(0.51,0.99)
)
# run posterior algorithm for simulated data:
out <- sampler(simu_dat,model_options0,mcmc_options0)
Hello there!
I was working through your example code in
example(sampler)
and when I runout <- sampler(simu_dat,model_options0,mcmc_options0)
for the first example, I get the following error:Error in log_p[t + 1] <- log_v[t + 1] - log_v[t] + log(b) + log_marginal(dat[i, : replacement has length zero
. I was wondering if you have any insights on how to resolve this? Below is all the code I've run and sessionInfoThe text was updated successfully, but these errors were encountered: