Exemple #1
0
arma::mat lin_pred_matF_svft(const field<vec>& Xbetas, const field<mat>& Z,
                             const mat& b, const field<mat>& U,
                             const field<uvec>& RE_inds, const field<uvec>& id,
                             const field<uvec>& col_inds, const uvec& row_inds,
                             const int& nrows, const int& ncols,
                             const CharacterVector& trans_Funs) {
    int n_field = Xbetas.size();
    mat out = mat(nrows, ncols, fill::zeros);
    for (int i = 0; i < n_field; ++i) {
        mat bb = b.cols(RE_inds.at(i));
        vec Zb = sum(Z.at(i) % bb.rows(id.at(i)), 1);
        if (trans_Funs[i] == "identity") {
            out.submat(row_inds, col_inds.at(i)) = U.at(i).each_col() % (Xbetas.at(i) + Zb);
        } else if (trans_Funs[i] == "expit") {
            vec exp_eta = exp(Xbetas.at(i) + Zb);
            out.submat(row_inds, col_inds.at(i)) = U.at(i).each_col() % (exp_eta / (1 + exp_eta));
        } else if (trans_Funs[i] == "exp") {
            out.submat(row_inds, col_inds.at(i)) = U.at(i).each_col() % exp(Xbetas.at(i) + Zb);
        } else if (trans_Funs[i] == "log") {
            out.submat(row_inds, col_inds.at(i)) = U.at(i).each_col() % log(Xbetas.at(i) + Zb);
        } else if (trans_Funs[i] == "log2") {
            out.submat(row_inds, col_inds.at(i)) = U.at(i).each_col() % log2(Xbetas.at(i) + Zb);
        } else if (trans_Funs[i] == "log10") {
            out.submat(row_inds, col_inds.at(i)) = U.at(i).each_col() % log10(Xbetas.at(i) + Zb);
        } else if (trans_Funs[i] == "sqrt") {
            out.submat(row_inds, col_inds.at(i)) = U.at(i).each_col() % sqrt(Xbetas.at(i) + Zb);
        }
    }
    return(out);
}
Exemple #2
0
arma::vec log_longF_svft(const field<vec>& y, const field<vec>& eta,
                         const CharacterVector& fams, const CharacterVector& links,
                         const List& sigmas, const field<uvec>& id, const int& n) {
    int n_outcomes = y.size();
    vec out(n, fill::zeros);
    for (int i = 0; i < n_outcomes; ++i) {
        uvec id_i = id.at(i);
        vec y_i = y.at(i);
        vec eta_i = eta.at(i);
        if (fams[i] == "gaussian") {
            double sigma_i = as<double>(sigmas[i]);
            vec log_dens = - 0.5 * pow((y_i - eta_i) / sigma_i, 2);
            out += rowsum_svft(log_dens, id_i);
        } else if (fams[i] == "binomial") {
            if (links[i] == "logit") {
                vec pr = exp(eta_i) / (1 + exp(eta_i));
                vec log_dens = y_i % log(pr) + (1 - y_i) % log(1 - pr);
                out += rowsum_svft(log_dens, id_i);
            } else if (links[i] == "probit") {
                vec pr = Vpnorm_svft(eta_i);
                vec log_dens = y_i % log(pr) + (1 - y_i) % log(1 - pr);
                out += rowsum_svft(log_dens, id_i);
            } else if (links[i] == "cloglog") {
                vec pr = - exp(- exp(eta_i)) + 1;
                vec log_dens = y_i % log(pr) + (1 - y_i) % log(1 - pr);
                out += rowsum_svft(log_dens, id_i);
            }
        } else if (fams[i] == "poisson") {
            vec mu = exp(eta_i);
            vec log_dens = y_i % log(mu) - mu;
            out += rowsum_svft(log_dens, id_i);
        }
    }
    return(out);
}
Exemple #3
0
arma::field<arma::vec> lin_predF_svft(const field<vec>& Xbetas, const field<mat>& Z,
                                      const mat& b, const field<uvec>& RE_inds,
                                      const field<uvec>& id) {
    signed int n_field = Xbetas.size();
    field<vec> out(n_field);
    for (int i = 0; i < n_field; ++i) {
        mat bb = b.cols(RE_inds.at(i));
        vec Zb = sum(Z.at(i) % bb.rows(id.at(i)), 1);
        out.at(i) = Xbetas.at(i) + Zb;
    }
    return(out);
}