当前位置: 首页>>代码示例>>C++>>正文


C++ LinearRegression::FitLinearModel方法代码示例

本文整理汇总了C++中LinearRegression::FitLinearModel方法的典型用法代码示例。如果您正苦于以下问题:C++ LinearRegression::FitLinearModel方法的具体用法?C++ LinearRegression::FitLinearModel怎么用?C++ LinearRegression::FitLinearModel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在LinearRegression的用法示例。


在下文中一共展示了LinearRegression::FitLinearModel方法的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;
};
开发者ID:zhanxw,项目名称:rvtests,代码行数:54,代码来源:testLinearRegression.cpp

示例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;
}
开发者ID:marisacgarre,项目名称:rvtests,代码行数:87,代码来源:DataLoader.cpp


注:本文中的LinearRegression::FitLinearModel方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。