[R-gregmisc-commits] r2137 - pkg/gmodels/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Aug 15 21:05:25 CEST 2016


Author: warnes
Date: 2016-08-15 21:05:23 +0200 (Mon, 15 Aug 2016)
New Revision: 2137

Added:
   pkg/gmodels/R/est_p_ci.R
Log:
Add est_p_ci generic and lm method

Added: pkg/gmodels/R/est_p_ci.R
===================================================================
--- pkg/gmodels/R/est_p_ci.R	                        (rev 0)
+++ pkg/gmodels/R/est_p_ci.R	2016-08-15 19:05:23 UTC (rev 2137)
@@ -0,0 +1,47 @@
+est_p_ci <- function(model, term, mult=1, digits=2, ...)
+  UseMethod("est_p_ci")
+
+est_p_ci.lm <- function(model, term, mult=1, digits=2, ...)
+{
+  info <- ci(model)
+  if(is.character(term) && !(term %in% rownames(info)))
+    stop(term, " is not a coefficient in model.")
+  info <- info[term,]
+  info.ci <- trim(format( round(mult * info[1:3], digits=digits) ))
+  if(mult < 0)
+    names(info.ci) <- rev(names(info.ci))
+  paste("Est=", info.ci[1],
+        " ",
+        "p=",format.pval(info['p-value'], digits=digits),
+        " ",
+        "95% CI: ",
+        info.ci['CI lower'],
+        " to ",
+        info.ci['CI upper'],
+        sep=""
+  )
+}
+
+est_p_ci.fit_contrast <- function(model, term, mult=1, digits=2, ...)
+{
+  if( !all(c("lower CI", "upper CI") %in% colnames(model) ) )
+    stop("object does not contain confidence interval information.")
+  
+  if(is.character(term) && !(term %in% rownames(info)))
+    stop(term, " is not a coefficient in model.")
+  
+  info.ci <- trim(format( round(mult * model[term, c("lower CI", "upper CI")], 
+                           digits=digits) )  )
+  if(mult < 0)
+    names(info.ci) <- rev(names(info.ci))
+  paste("Est=", info.ci[1],
+        " ",
+        "p=",format.pval(model[term, 'Pr(>|t|)'], digits=digits),
+        " ",
+        "95% CI: ",
+        info.ci["lower CI"],
+        " to ",
+        info.ci["upper CI"],
+        sep=""
+  )
+}



More information about the R-gregmisc-commits mailing list