Thread: [R-gregmisc-users] SF.net SVN: r-gregmisc: [1076] trunk/gmodels/R/ci.R
Brought to you by:
warnes
From: <wa...@us...> - 2007-03-09 20:07:05
|
Revision: 1076 http://svn.sourceforge.net/r-gregmisc/?rev=1076&view=rev Author: warnes Date: 2007-03-09 12:06:36 -0800 (Fri, 09 Mar 2007) Log Message: ----------- Minor code formatting changes Modified Paths: -------------- trunk/gmodels/R/ci.R Modified: trunk/gmodels/R/ci.R =================================================================== --- trunk/gmodels/R/ci.R 2007-03-09 20:06:05 UTC (rev 1075) +++ trunk/gmodels/R/ci.R 2007-03-09 20:06:36 UTC (rev 1076) @@ -3,21 +3,22 @@ ci <- function(x, confidence=0.95,alpha=1-confidence,...) UseMethod("ci") -ci.default <- function(x, confidence=0.95,alpha=1-confidence,na.rm=FALSE,...) { - est <- mean(x, na.rm=na.rm) - stderr <- sd(x, na.rm=na.rm)/sqrt(nobs(x)); - ci.low <- est + qt(alpha/2, nobs(x)-1) * stderr - ci.high <- est - qt(alpha/2, nobs(x)-1) * stderr - retval <- c( - Estimate=est, - "CI lower"=ci.low, - "CI upper"=ci.high, - "Std. Error"=stderr - ) +ci.default <- function(x, confidence=0.95,alpha=1-confidence,na.rm=FALSE,...) + { + est <- mean(x, na.rm=na.rm) + stderr <- sd(x, na.rm=na.rm)/sqrt(nobs(x)); + ci.low <- est + qt(alpha/2, nobs(x)-1) * stderr + ci.high <- est - qt(alpha/2, nobs(x)-1) * stderr + retval <- c( + Estimate=est, + "CI lower"=ci.low, + "CI upper"=ci.high, + "Std. Error"=stderr + ) + + retval + } - retval -} - ci.binom <- function(x, confidence=0.95,alpha=1-confidence,...) { if( !(all(x) %in% c(0,1)) ) stop("Binomial values must be either 0 or 1.") @@ -37,48 +38,55 @@ } ci.lm <- function(x,confidence=0.95,alpha=1-confidence,...) -{ - x <- summary(x) - est <- coef(x)[,1] ; - ci.low <- est + qt(alpha/2, x$df[2]) * coef(x)[,2] ; - ci.high <- est - qt(alpha/2, x$df[2]) * coef(x)[,2] ; - retval <- cbind(Estimate=est, - "CI lower"=ci.low, - "CI upper"=ci.high, - "Std. Error"= coef(x)[,2], - "p-value" = coef(x)[,4]) + { + x <- summary(x) + est <- coef(x)[,1] ; + ci.low <- est + qt(alpha/2, x$df[2]) * coef(x)[,2] ; + ci.high <- est - qt(alpha/2, x$df[2]) * coef(x)[,2] ; + retval <- cbind(Estimate=est, + "CI lower"=ci.low, + "CI upper"=ci.high, + "Std. Error"= coef(x)[,2], + "p-value" = coef(x)[,4]) + + reqtval + } - retval -} - ci.lme <- function(x,confidence=0.95,alpha=1-confidence,...) { - x <- summary(x) - est <- x$tTable[,"Value"] ; - ci.low <- est + qt(alpha/2, x$tTable[,"DF"]) * x$tTable[,"Std.Error"] ; - ci.high <- est - qt(alpha/2, x$tTable[,"DF"]) * x$tTable[,"Std.Error"] ; - retval <- cbind(Estimate=est, - "CI lower"=ci.low, - "CI upper"=ci.high, - "Std. Error"= x$tTable[,"Std.Error"], - "DF" = x$tTable[,"DF"], - "p-value" = x$tTable[,"p-value"]) - rownames(retval) <- rownames(x$tTable) - retval -} + x <- summary(x) + est <- x$tTable[,"Value"] ; + ci.low <- est + qt(alpha/2, x$tTable[,"DF"]) * x$tTable[,"Std.Error"] ; + ci.high <- est - qt(alpha/2, x$tTable[,"DF"]) * x$tTable[,"Std.Error"] ; + retval <- cbind(Estimate=est, + "CI lower"=ci.low, + "CI upper"=ci.high, + "Std. Error"= x$tTable[,"Std.Error"], + "DF" = x$tTable[,"DF"], + "p-value" = x$tTable[,"p-value"]) + rownames(retval) <- rownames(x$tTable) + retval + } -ci.lmer <- function(x, confidence=0.95, alpha=1-confidence, sim.lmer=TRUE, n.sim=1000, ...) ################### changed this function +ci.lmer <- function(x, + confidence=0.95, + alpha=1-confidence, + sim.lmer=TRUE, + n.sim=1000, + ... + ) { if(!(require(coda, quietly=TRUE) & require(Matrix, quietly=TRUE))) stop("coda and Matrix packages required for ci.lmer") x.effects <- fixef(x) n <- length(x.effects) - + retval <- est.lmer(obj = x, cm = diag(n), beta0 = rep(0, n), conf.int = confidence, show.beta0 = FALSE, - n.sim = n.sim)[,c("Estimate", "Lower.CI", "Upper.CI", "Std. Error", "p value")] - + n.sim = n.sim)[,c("Estimate", "Lower.CI", "Upper.CI", + "Std. Error", "p value")] + colnames(retval)[c(2:3, 5)] <- c("CI lower", "CI upper", "p-value") rownames(retval) <- names(x.effects) retval This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <wa...@us...> - 2007-03-09 22:35:14
|
Revision: 1079 http://svn.sourceforge.net/r-gregmisc/?rev=1079&view=rev Author: warnes Date: 2007-03-09 14:35:13 -0800 (Fri, 09 Mar 2007) Log Message: ----------- Remove stray character Modified Paths: -------------- trunk/gmodels/R/ci.R Modified: trunk/gmodels/R/ci.R =================================================================== --- trunk/gmodels/R/ci.R 2007-03-09 20:10:58 UTC (rev 1078) +++ trunk/gmodels/R/ci.R 2007-03-09 22:35:13 UTC (rev 1079) @@ -49,7 +49,7 @@ "Std. Error"= coef(x)[,2], "p-value" = coef(x)[,4]) - reqtval + retval } ci.lme <- function(x,confidence=0.95,alpha=1-confidence,...) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |