[Rcpp-commits] r4361 - in pkg/RcppGSL: . src
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Fri Jun 21 23:30:01 CEST 2013
Author: edd
Date: 2013-06-21 23:30:00 +0200 (Fri, 21 Jun 2013)
New Revision: 4361
Modified:
pkg/RcppGSL/ChangeLog
pkg/RcppGSL/src/fastLm.cpp
Log:
minor improvement for computing std. error
Modified: pkg/RcppGSL/ChangeLog
===================================================================
--- pkg/RcppGSL/ChangeLog 2013-06-21 11:50:21 UTC (rev 4360)
+++ pkg/RcppGSL/ChangeLog 2013-06-21 21:30:00 UTC (rev 4361)
@@ -5,6 +5,8 @@
* cleanup: Take some tasks that the vignette/Makefile had
+ * src/fastLm.cpp: Minor improvement in computing std.error of est.
+
2013-06-19 Dirk Eddelbuettel <edd at debian.org>
* vignettes/RcppGSL/RcppGSL-intro.Rnw: Some fixes
Modified: pkg/RcppGSL/src/fastLm.cpp
===================================================================
--- pkg/RcppGSL/src/fastLm.cpp 2013-06-21 11:50:21 UTC (rev 4360)
+++ pkg/RcppGSL/src/fastLm.cpp 2013-06-21 21:30:00 UTC (rev 4361)
@@ -2,7 +2,7 @@
//
// fastLm.cpp: Rcpp and GSL based implementation of lm
//
-// Copyright (C) 2010 Dirk Eddelbuettel and Romain Francois
+// Copyright (C) 2010 - 2013 Dirk Eddelbuettel and Romain Francois
//
// This file is part of RcppGSL.
//
@@ -41,15 +41,12 @@
gsl_multifit_linear_workspace *work = gsl_multifit_linear_alloc (n, k);
gsl_multifit_linear (X, y, coef, cov, &chisq, work);
gsl_multifit_linear_free (work);
-
- // extract the diagonal as a vector view
- gsl_vector_view diag = gsl_matrix_diagonal(cov) ;
-
- // currently there is not a more direct interface in Rcpp::NumericVector
- // that takes advantage of wrap, so we have to do it in two steps
- Rcpp::NumericVector std_err ; std_err = diag;
- std::transform( std_err.begin(), std_err.end(), std_err.begin(), sqrt );
+ // assign diagonal to a vector, then take square roots to get std.error
+ Rcpp::NumericVector std_err;
+ std_err = gsl_matrix_diagonal(cov); // need two step decl. and assignment
+ std_err = sqrt(std_err); // sqrt() is an Rcpp sugar function
+
Rcpp::List res = Rcpp::List::create(Rcpp::Named("coefficients") = coef,
Rcpp::Named("stderr") = std_err,
Rcpp::Named("df.residual") = n - k);
More information about the Rcpp-commits
mailing list