[Rcpp-commits] r3055 - pkg/RcppEigen/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Jun 13 23:01:12 CEST 2011


Author: dmbates
Date: 2011-06-13 23:01:12 +0200 (Mon, 13 Jun 2011)
New Revision: 3055

Modified:
   pkg/RcppEigen/R/fastLm.R
Log:
Associate names with coefficients.  Clean up fastLm.  Forward the object through summary.


Modified: pkg/RcppEigen/R/fastLm.R
===================================================================
--- pkg/RcppEigen/R/fastLm.R	2011-06-13 20:59:24 UTC (rev 3054)
+++ pkg/RcppEigen/R/fastLm.R	2011-06-13 21:01:12 UTC (rev 3055)
@@ -32,6 +32,7 @@
     y <- as.numeric(y)
 
     res <- fastLmPure(y, X)
+    names(res$coefficients) <- colnames(X)
     res$call <- match.call()
 
     class(res) <- "fastLm"
@@ -49,34 +50,24 @@
     se <- object$stderr
     tval <- coef(object)/se
 
-    TAB <- cbind(Estimate = coef(object),
-                 StdErr = se,
-                 t.value = tval,
-                 p.value = 2*pt(-abs(tval), df=object$df))
+    object$coefficients <- cbind(Estimate = object$coefficients,
+                                 StdErr   = se,
+                                 t.value  = tval,
+                                 p.value  = 2*pt(-abs(tval), df=object$df))
 
-    # why do I need this here?
-    rownames(TAB) <- names(object$coefficients)
-    colnames(TAB) <- c("Estimate", "StdErr", "t.value", "p.value")
-
     ## cf src/stats/R/lm.R and case with no weights and an intercept
     f <- object$fitted.values
     r <- object$residuals
     mss <- sum((f - mean(f))^2)
     rss <- sum(r^2)
 
-    r.squared <- mss/(mss + rss)
+    object$r.squared <- mss/(mss + rss)
     df.int <- 1 		# case of intercept
     n <- length(f)
     rdf <- object$df
-    adj.r.squared <- 1 - (1 - r.squared) * ((n - df.int)/rdf)
-
-    res <- list(call=object$call,
-                coefficients=TAB,
-                r.squared=r.squared,
-                adj.r.squared=adj.r.squared)
-
-    class(res) <- "summary.fastLm"
-    res
+    object$adj.r.squared <- 1 - (1 - object$r.squared) * ((n - df.int)/rdf)
+    class(object) <- "summary.fastLm"
+    object
 }
 
 print.summary.fastLm <- function(x, ...) {
@@ -86,6 +77,8 @@
 
     printCoefmat(x$coefficients, P.values=TRUE, has.Pvalue=TRUE)
     digits <- max(3, getOption("digits") - 3)
+    cat("\nResidual standard error: ", formatC(x$s, digits=digits), " on ",
+        formatC(x$df), " degrees of freedom\n", sep="")
     cat("Multiple R-squared: ", formatC(x$r.squared, digits=digits),
         ",\tAdjusted R-squared: ",formatC(x$adj.r.squared, digits=digits),
         "\n", sep="")
@@ -98,6 +91,7 @@
     y <- model.response(mf)
 
     res <- fastLm.default(x, y, ...)
+    names(res$coefficients) <- colnames(x)
     res$call <- match.call()
     res$formula <- formula
     res



More information about the Rcpp-commits mailing list