本文整理汇总了C++中CData::Y方法的典型用法代码示例。如果您正苦于以下问题:C++ CData::Y方法的具体用法?C++ CData::Y怎么用?C++ CData::Y使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CData
的用法示例。
在下文中一共展示了CData::Y方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Initialize
void CParam::Initialize(CData &Data){
n_pheno = Data.Y.n_rows ; n_SNP = Data.Y.n_cols ; // constants but stored in CParam for convienence
Data.logY = arma::zeros<arma::mat>(n_pheno,n_SNP) ;
// Note 1. This is used to calculate sum of log y_it when e_it=1.
// 2. (Weak signal) Because e_it=0 with y_it <= 0 by definition (model assumption),
// we will not use log y_it for e_it=0 and store zero here.
// 3. (Strong signal) Also, we put e_it=1 when y_it > threshold // V 1.3.1
for (int i_pheno=0; i_pheno<n_pheno; i_pheno++ ){
for (int i_SNP=0; i_SNP<n_SNP; i_SNP++ ){
if ( Data.Y(i_pheno,i_SNP) > 0){ // V 2.0.2
Data.logY(i_pheno,i_SNP) = log(Data.Y(i_pheno,i_SNP)) ;
if ( Data.Y(i_pheno,i_SNP) > Data.threshold_on ) E_mat(i_pheno,i_SNP) = 1 ;
} else {
E_mat(i_pheno,i_SNP) = 0 ;
}
}
}
normC = normC_fn(Beta, Data) ; // Ver_1_4_1
if ( normC < 0 ){
Rcpp::stop("The initialized normC has a negative value.") ;
}
Data.msg_level = 0; //0 errors only; 1: errors and warnings; 2: errors, warnings and information
sum_E_ijt = arma::zeros<arma::cube>(n_pheno,n_pheno,n_SNP) ;
is_initialized = 1 ;
}
示例2: Beta
void CParam::S1_e_it(CData &Data) {
for (int i_SNP=0; i_SNP<n_SNP; i_SNP++){
for (int i=0; i<n_pheno; i++){
if ( ( Data.Y(i,i_SNP) > 0 ) & ( Data.Y(i,i_SNP) <= Data.threshold_on ) ){
// V 1.3.1 -> other case: e_it is fixed in CParam::Initialize,
// i.e., e_it=0 if y_it<=0 and 1 if y_it>=Data.threshold_on
double unnorm_logprob0 = 0.0 ;
double unnorm_logprob1 = Beta(i,i) ;
for (int j=0; j<n_pheno; j++){
if (G_mat(i,j)==1) unnorm_logprob1 = unnorm_logprob1 + Beta(i,j) * E_mat(j,i_SNP) ;
}
// Note: Not count G_mat(i,j)=0 or G_mat(i,j)=9,i.e., diagonal
unnorm_logprob0 = unnorm_logprob0 + R::dnorm(Data.Y(i,i_SNP),0,1,1) ; // log = T
unnorm_logprob1 = unnorm_logprob1 + R::dlnorm(Data.Y(i,i_SNP),mu_vec(i),sqrt(sig2_vec(i)),1) ; // log = T
double prob_e_it = 1.0 / ( 1.0 + exp(unnorm_logprob0-unnorm_logprob1) ) ;
// Note: p1 = f1/(f1+f0) = 1 / (1+f0/f1) = 1 / (1+exp(log f0 - log f1))
RandVec = Rcpp::runif(1,0,1) ;
if ( prob_e_it >= RandVec(0) ){
E_mat(i,i_SNP) = 1 ;
} else {
E_mat(i,i_SNP) = 0 ;
}
}
// To check loglikelihood
if (E_mat(i,i_SNP)==1){
loglikelihood = loglikelihood + R::dlnorm(Data.Y(i,i_SNP),mu_vec(i),sqrt(sig2_vec(i)),1) ;
} else {
loglikelihood = loglikelihood + R::dnorm(Data.Y(i,i_SNP),0,1,1) ;
}
}
}
is_accept_vec(0) = 1 ;
}