[Rcpp-commits] r3691 - in pkg/RcppArmadillo: . R inst

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Jul 14 18:14:48 CEST 2012


Author: edd
Date: 2012-07-14 18:14:47 +0200 (Sat, 14 Jul 2012)
New Revision: 3691

Modified:
   pkg/RcppArmadillo/ChangeLog
   pkg/RcppArmadillo/R/fastLm.R
   pkg/RcppArmadillo/inst/NEWS
Log:
 o correct summary method for formula when using a formula
 o also report residual summary


Modified: pkg/RcppArmadillo/ChangeLog
===================================================================
--- pkg/RcppArmadillo/ChangeLog	2012-07-12 01:01:32 UTC (rev 3690)
+++ pkg/RcppArmadillo/ChangeLog	2012-07-14 16:14:47 UTC (rev 3691)
@@ -1,3 +1,11 @@
+2012-07-14  Dirk Eddelbuettel  <edd at debian.org>
+
+	* R/fastLm.R (fastLm.formula): Note whether intercept in formula or
+	not; also store the result of summary() on residuals
+	* R/fastLm.R (print.summary.fastLm): Display summary of residuals 
+	* R/fastLm.R (summary.fastLm): Distinguish between the intercept and
+	no-intercept cases when computing R^2
+
 2012-07-11  Dirk Eddelbuettel  <edd at debian.org>
 
 	* DESCRIPTION: Release 0.3.2.4

Modified: pkg/RcppArmadillo/R/fastLm.R
===================================================================
--- pkg/RcppArmadillo/R/fastLm.R	2012-07-12 01:01:32 UTC (rev 3690)
+++ pkg/RcppArmadillo/R/fastLm.R	2012-07-14 16:14:47 UTC (rev 3691)
@@ -65,16 +65,18 @@
 
     # why do I need this here?
     rownames(TAB) <- names(object$coefficients)
-#    colnames(TAB) <- c("Estimate", "StdErr", "t.value", "p.value")
+    colnames(TAB) <- c("Estimate", "StdErr", "t.value", "p.value")
 
-    ## cf src/stats/R/lm.R and case with no weights and an intercept
+    ## cf src/library/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)
+    #mss <- sum((f - mean(f))^2)
+    mss <- if (object$intercept) sum((f - mean(f))^2) else sum(f^2)
     rss <- sum(r^2)
 
     r.squared <- mss/(mss + rss)
-    df.int <- 1 		# case of intercept
+    df.int <- if (object$intercept) 1L else 0L
+
     n <- length(f)
     rdf <- object$df
     adj.r.squared <- 1 - (1 - r.squared) * ((n - df.int)/rdf)
@@ -82,7 +84,8 @@
     res <- list(call=object$call,
                 coefficients=TAB,
                 r.squared=r.squared,
-                adj.r.squared=adj.r.squared)
+                adj.r.squared=adj.r.squared,
+                residSum=summary(object$residuals, digits=5)[-4])
 
     class(res) <- "summary.fastLm"
     res
@@ -91,6 +94,8 @@
 print.summary.fastLm <- function(x, ...) {
     cat("\nCall:\n")
     print(x$call)
+    cat("\nResiduals:\n")
+    print(x$residSum)
     cat("\n")
 
     printCoefmat(x$coefficients, P.values=TRUE, has.Pvalue=TRUE)
@@ -109,6 +114,7 @@
     res <- fastLm.default(x, y, ...)
     res$call <- match.call()
     res$formula <- formula
+    res$intercept <- attr(attr(mf, "terms"), "intercept")
     res
 }
 

Modified: pkg/RcppArmadillo/inst/NEWS
===================================================================
--- pkg/RcppArmadillo/inst/NEWS	2012-07-12 01:01:32 UTC (rev 3690)
+++ pkg/RcppArmadillo/inst/NEWS	2012-07-14 16:14:47 UTC (rev 3691)
@@ -1,3 +1,8 @@
+0.3.x.y  2012-xx-yy
+
+    o   Corrected summary method to deal with the no intercept case when
+        using a formula; also display residual summary() statistics
+
 0.3.2.4  2012-07-11
 
     o   Upgraded to Armadillo release 3.2.4



More information about the Rcpp-commits mailing list