| get_moments_cpp_eco | R Documentation | 
update only selected moments that need update when iterating over u (except for rmat)
get_moments_cpp_eco( leaves_u, E_beta, E_beta_sq, E_eta, E_eta_sq, prob, prob_gamma, mu_gamma, sigma_gamma, mu_alpha, Sigma_alpha, anc, cardanc )
leaves_u | 
 the leaf descendant node ids for node u  | 
E_beta, E_beta_sq, E_eta, E_eta_sq | 
 moment updates produced by   | 
prob | 
 variational probabilities for   | 
prob_gamma | 
 should be fixed:   | 
mu_gamma | 
 variational Gaussian means (for   | 
sigma_gamma | 
 variational Gaussian variances (for   | 
mu_alpha | 
 variational Gaussian mean vectors (for   | 
Sigma_alpha | 
 variational Gaussian variances (for  
  | 
anc | 
 a list of pL vectors, each vector has the node ids of the ancestors; lengths may differ. The ancestors include the node concerned.  | 
cardanc | 
 a numeric vector of length pL; integers. The number of ancestors for each leaf node  | 
(one-node version of get_moments_cpp)
a List
return List::create(Named("E_beta")=E_beta, Named("E_beta_sq")=E_beta_sq, Named("E_eta")=E_eta, Named("E_eta_sq")=E_eta_sq);
# illustrates the calculation of the various moments:
prob = 0.2
mu1 = 2
mu0 = 0
sigma1 = 3
sigma0 = 1
N = 10000
s = rbinom(N,1,prob)
y <- rep(NA,length(s))
for (i in seq_along(s)){
      y[i] <- rnorm(1,mu1,sqrt(sigma1))*s[i] +
        rnorm(1,mu0,sqrt(sigma0))*(1-s[i])
}
var(s*y)
prob*(sigma1+(1-prob)*mu1^2)
mean(y^2)
prob*(sigma1+mu1^2) + (1-prob)*sigma0
mean(s*y^2)
prob*(sigma1+mu1^2)
mean(s*y)
prob*mu1
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.