本文整理汇总了C++中LinearRegression::GetCovEst方法的典型用法代码示例。如果您正苦于以下问题:C++ LinearRegression::GetCovEst方法的具体用法?C++ LinearRegression::GetCovEst怎么用?C++ LinearRegression::GetCovEst使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LinearRegression
的用法示例。
在下文中一共展示了LinearRegression::GetCovEst方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char* argv[]) {
LinearRegression lr;
LinearRegressionScoreTest lrst;
LinearRegressionPermutationTest lrpt;
Vector y;
Matrix x;
LoadVector("input.y", y);
LoadMatrix("input.x", x);
if (lr.FitLinearModel(x, y) == false) {
fprintf(stderr, "Fitting failed!\n");
return -1;
}
Vector& beta = lr.GetCovEst();
Matrix& v = lr.GetCovB();
Vector& pWald = lr.GetAsyPvalue();
fprintf(stdout, "wald_beta\t");
Print(beta);
fputc('\n', stdout);
fprintf(stdout, "wald_vcov\t");
Print(v);
fputc('\n', stdout);
fprintf(stdout, "wald_p\t");
Print(pWald[1]);
fputc('\n', stdout);
if (lrpt.FitLinearModel(x, 1, y, 200, 0.05) == false) {
fprintf(stderr, "Fitting failed!\n");
return -1;
}
fprintf(stdout, "permutation_p\t");
double permu_p = lrpt.getPvalue();
Print(permu_p);
fputc('\n', stdout);
if (lrst.FitLinearModel(x, y, 1) == false) {
fprintf(stderr, "Fitting failed!\n");
return -1;
}
fprintf(stdout, "score_p\t");
double score_p = lrst.GetPvalue();
Print(score_p);
fputc('\n', stdout);
return 0;
};
示例2: useResidualAsPhenotype
int DataLoader::useResidualAsPhenotype() {
if (binaryPhenotype) {
logger->warn(
"WARNING: Skip transforming binary phenotype, although you want to "
"use residual as phenotype!");
return 0;
}
LinearRegression lr;
Vector pheno;
Matrix covAndInt;
const int numCovariate = covariate.ncol();
copyPhenotype(phenotype, &pheno);
copyCovariateAndIntercept(pheno.Length(), covariate, &covAndInt);
if (!lr.FitLinearModel(covAndInt, pheno)) {
if (numCovariate > 0) {
logger->error(
"Cannot fit model: [ phenotype ~ 1 + covariates ], now use the "
"original phenotype");
} else {
logger->error(
"Cannot fit model: [ phenotype ~ 1 ], now use the "
"original phenotype");
}
} else { // linear model fitted successfully
copyVectorToMatrixColumn(lr.GetResiduals(), &phenotype, 0);
// const int n = lr.GetResiduals().Length();
// for (int i = 0; i < n; ++i) {
// // phenotypeInOrder[i] = lr.GetResiduals()[i];
// phenotype[i][0] = lr.GetResiduals()[i];
// }
covariate.clear();
if (numCovariate > 0) {
logger->info(
"DONE: Fit model [ phenotype ~ 1 + covariates ] and model "
"residuals will be used as responses");
} else {
logger->info("DONE: Use residual as phenotype by centerng it");
}
// store fitting results
Vector& beta = lr.GetCovEst();
Matrix& betaSd = lr.GetCovB();
const int n = beta.Length();
for (int i = 0; i < n; ++i) {
addFittedParameter(covAndInt.GetColumnLabel(i), beta[i], betaSd[i][i]);
}
addFittedParameter("Sigma2", lr.GetSigma2(), NAN);
}
#if 0
if (covariate.ncol() > 0) {
LinearRegression lr;
Vector pheno;
Matrix covAndInt;
copyPhenotype(phenotype, &pheno);
copyCovariateAndIntercept(covariate.nrow(), covariate, &covAndInt);
if (!lr.FitLinearModel(covAndInt, pheno)) {
logger->error(
"Cannot fit model: [ phenotype ~ 1 + covariates ], now use the "
"original phenotype");
} else {
const int n = lr.GetResiduals().Length();
for (int i = 0; i < n; ++i) {
// phenotypeInOrder[i] = lr.GetResiduals()[i];
phenotype[i][0] = lr.GetResiduals()[i];
}
covariate.clear();
logger->info(
"DONE: Fit model [ phenotype ~ 1 + covariates ] and model "
"residuals will be used as responses");
}
storeFittedModel(lr);
} else { // no covaraites
// centerVector(&phenotypeInOrder);
std::vector<double> v;
phenotype.extractCol(0, &v);
centerVector(&v);
phenotype.setCol(0, v);
logger->info("DONE: Use residual as phenotype by centerng it");
}
#endif
return 0;
}