epibasix/0000755000176200001440000000000013374642443012070 5ustar liggesusersepibasix/NAMESPACE0000755000176200001440000000142113374623312013302 0ustar liggesusers# Exports all functions not beginning with a period. exportPattern("^[^\\.]") #Import other helper functions importFrom("stats", "cor", "fisher.test", "median", "pchisq", "pnorm", "pt", "qnorm", "qt", "sd", "shapiro.test", "var") #Register S3 S3method(print, corXY) S3method(print, diffDetect) S3method(print, epi2x2) S3method(print, epiKappa) S3method(print, epiTTest) S3method(print, mcNemar) S3method(print, n4means) S3method(print, n4props) S3method(print, sensSpec) S3method(print, univar) S3method(summary, corXY) S3method(summary, diffDetect) S3method(summary, epi2x2) S3method(summary, epiKappa) S3method(summary, epiTTest) S3method(summary, mcNemar) S3method(summary, n4means) S3method(summary, n4props) S3method(summary, sensSpec) S3method(summary, univar)epibasix/R/0000755000176200001440000000000013374623526012272 5ustar liggesusersepibasix/R/epiTTest.R0000755000176200001440000000755211150620750014154 0ustar liggesusersepiTTest <- function(X,Y,alpha=0.05, pooled=FALSE, digits=3) { #Error Checking if (!is.vector(X)) stop("Sorry, X and Y must be vectors...") if (!is.vector(Y)) stop("Sorry, X and Y must be vectors...") if ((alpha >= 1) || (alpha <= 0)) stop("Sorry, the alpha must lie within (0,1)") #Initialize Object and Calculate simple statistics r <- NULL; r$digits <- digits; r$alpha <- alpha; r$pooled <- pooled; r$nx <- length(X) r$ny <- length(Y) r$mean.x <- mean(X) r$mean.y <- mean(Y) r$s.x <- sd(X) r$s.y <- sd(Y) r$d <- r$mean.x - r$mean.y; #Uses pooled estimates of variance if (pooled) { r$df <- r$nx + r$ny -2; r$s2p <- ((r$nx - 1)*var(X) +(r$ny -1)*var(Y))/r$df r$CIL <- r$d - qt(1-alpha/2, r$df)*sqrt(r$s2p*((1/r$nx) + (1/r$ny))); r$CIU <- r$d + qt(1-alpha/2, r$df)*sqrt(r$s2p*((1/r$nx) + (1/r$ny))); r$TStat <- abs(r$d)/sqrt(r$s2p*((1/r$nx) + (1/r$ny))); r$p.value <- 2* (1 - pt(r$TStat, r$df)) } #Uses Satter. Approximation if (!pooled) { r$df <- floor( (var(X)/r$nx + var(Y)/r$ny)^2/( (var(X)/r$nx)^2/(r$nx -1) + (var(Y)/r$ny)^2/(r$ny-1) )); r$CIL <- r$d - qt(1-alpha/2, r$df)*sqrt(var(X)/r$nx + var(Y)/r$ny) r$CIU <- r$d + qt(1-alpha/2, r$df)*sqrt(var(X)/r$nx + var(Y)/r$ny) r$TStat <- abs(r$d)/sqrt(var(X)/r$nx + var(Y)/r$ny); r$p.value <- 2*(1 - pt(r$TStat, r$df)) } class(r) <- "epiTTest" return(r); } #Print Method print.epiTTest <- function(x, ...) { cat("Epidemiological T-Test Analysis", "\n \n") cat("Number of Observations in Group I: ", x$nx, "\n", sep="") cat("Number of Observations in Group II: ", x$ny, "\n \n", sep="") cat("Sample Difference Between Means: ", round(x$d, digits=x$digits), "\n", sep="") cat(100*(1-x$alpha), "% Confidence Limits for true mean difference: [", round(x$CIL,digits=x$digits), ", ", round(x$CIU,digits=x$digits),"]", "\n \n", sep=""); if (x$pooled) { cat("Note: The above Analysis uses a pooled estimate of the variance. \n") } if (!x$pooled) { cat("Note: The above Analysis uses the Satterthwaite estimate of the variance. \n") } } #Summary Method summary.epiTTest <- function(object, ...) { cat("Epidemiological T-Test Analysis", "\n \n") cat("Number of Observations in Group I: ", object$nx, "\n", sep="") cat("Sample Mean for Group I: ", round(object$mean.x, digits=object$digits), " with a sample standard deviation of ", round(object$s.x, digits=object$digits), "\n", sep=""); cat("Number of Observations in Group II: ", object$ny, "\n", sep="") cat("Sample Mean for Group II: ", round(object$mean.y, digits=object$digits), " with a sample standard deviation of ", round(object$s.y, digits=object$digits), "\n", sep=""); if (object$pooled) { cat("Sample Difference Between Means: ", round(object$d, digits=object$digits), " with a pooled standard deviation of ", round(sqrt(object$s2p), digits=object$digits), "\n", sep=""); cat(100*(1-object$alpha), "% Confidence Limits for true mean difference: [", round(object$CIL,digits=object$digits), ", ", round(object$CIU,digits=object$digits),"]", "\n \n", sep=""); cat("T-Statistic for H0: difference = 0 vs. HA: difference != 0 is ", round(object$TStat,digits=object$digits), " with a p.value of ", round(object$p.value, digits=object$digits), "\n \n", sep=""); cat("Note: The above Analysis uses a pooled estimate of the variance. \n") } if (!object$pooled) { cat("Sample Difference Between Means: ", round(object$d, digits=object$digits), "\n", sep="") cat(100*(1-object$alpha), "% Confidence Limits for true mean difference: [", round(object$CIL,digits=object$digits), ", ", round(object$CIU,digits=object$digits),"]", "\n \n", sep=""); cat("T-Statistic for H0: difference = 0 vs. HA: difference != 0 is ", round(object$TStat,digits=object$digits), " with a p.value of ", round(object$p.value, digits=object$digits), "\n \n", sep=""); cat("Note: The above Analysis uses the Satterthwaite estimate of the variance. \n") } }epibasix/R/diffDetect.R0000755000176200001440000000350111150620652014443 0ustar liggesusersdiffDetect <- function(N,sigma,alpha=0.05, power=0.8, two.tailed=TRUE) { #Error Checking if ((alpha >= 1) || (alpha <= 0) || (power <= 0) || (power >= 1)) stop("Sorry, the alpha and power must lie within (0,1)") for (i in 1:length(N)) { if (N[i] <= 0) { stop("Sorry, the specified values of N must be strictly positive...") } } for (i in 1:length(sigma)) { if (sigma[i] <=0) stop("Sorry, the specified value of sigma must be strictly positive...") } #Initialize Parameters r <- NULL; r$n <- N; r$sigma <- sigma; r$alpha <- alpha; r$power <- power; r$two.tailed <- two.tailed; r$delta <- matrix(0,nrow=length(N), ncol=length(sigma)); #Label rows and columns colnames(r$delta) <- sigma; rownames(r$delta) <- N; #Compute delta for one/two-sided test if (two.tailed) { for (i in 1:length(N)) { for (j in 1:length(sigma)) { r$delta[i,j] <- (qnorm(1 - alpha/2) + qnorm(power))*sqrt((2*sigma[j]^2)/N[i]); } } } if (!two.tailed) { for (i in 1:length(N)) { for (j in 1:length(sigma)) { r$delta[i,j] <- (qnorm(1 - alpha) + qnorm(power))*sqrt((2*sigma[j]^2)/N[i]); } } } class(r) <- "diffDetect"; return(r); } #Print Method print.diffDetect <- function(x, ...) { cat("The Minimum Detectable Difference between two populations for fixed N (in rows) and sigma (in columns) is: \n \n"); print(x$delta) } #Summary Method summary.diffDetect <- function(object, ...) { cat("The Minimum Detectable Difference between two populations for fixed N (in rows) and sigma (in columns) is: \n \n"); print(object$delta) cat("\n This assumes: \n") cat("Type I Error Rate (alpha) = ", object$alpha, " (with two.tailed=", object$two.tailed, ") and Power = ", object$power, "\n \n",sep="") cat("Note: Original N and Sigma Vectors are available as $n and $sigma \n") }epibasix/R/n4means.R0000755000176200001440000000356511150621024013753 0ustar liggesusersn4means <- function(delta, sigma, alpha=0.05, power=0.8, AR=1, two.tailed=TRUE, digits=3) { #Error Checking if (sigma <=0) stop("Sorry, the specified value of sigma must be strictly positive...") if ((alpha >= 1) || (alpha <= 0) || (power <= 0) || (power >= 1)) stop("Sorry, the alpha and power must lie within (0,1)") if (AR <=0) stop("Sorry, the specified value of the Allocation Ratio (AR) must be strictly positive...") #Initialize Parameters r <- NULL r$delta <- delta; r$sigma <- sigma; r$alpha <- alpha; r$power <- power; r$two.tailed <- two.tailed; r$AR <- AR; #Calculate nE and nC for one or two tailed alpha if (two.tailed) { r$n <- 2*sigma^2*(qnorm(1 - alpha/2) + qnorm(power))^2/(delta^2); r$nE <- (1/2)*r$n*(1 + (1/AR)); r$nC <- (1/2)*r$n*(1 + AR); } if (!two.tailed) { r$n <- 2*sigma^2*(qnorm(1 - alpha) + qnorm(power))^2/(delta^2); r$nE <- (1/2)*r$n*(1 + (1/AR)); r$nC <- (1/2)*r$n*(1 + AR); } class(r) <- "n4means"; return(r); } #Print method print.n4means <- function(x, ...) { cat("The required sample size is a minimum of ", ceiling(x$nE), " individuals in the Experimental Group \n", sep="") cat(" and a minimum of ", ceiling(x$nC), " individuals in the Control Group. \n", sep="") } #Summary Method summary.n4means <- function(object, ...) { cat("Sample Size Calculation for Difference Between Means of Two Populations", "\n \n") cat("Assuming:", "\n") cat("Desired Minimum Detectable Difference between groups, delta = ", object$delta, "\n") cat("Sigma = ", object$sigma, "\n"); cat("Type I Error Rate (alpha) = ", object$alpha, " and Power = ", object$power, "\n \n",sep="") cat("The required sample size is a minimum of ", ceiling(object$nE), " individuals in the Experimental Group \n", sep="") cat(" and a minimum of ", ceiling(object$nC), " individuals in the Control Group. \n", sep="") }epibasix/R/epi2x2.R0000755000176200001440000001122313374623526013530 0ustar liggesusersepi2x2 <- function(X, alpha=0.05, digits=3) { #Error Checking if (nrow(X) != ncol(X)) stop("Sorry, 'X' must be a 2x2 Matrix...") if ((alpha >= 1) || (alpha <= 0)) stop("Sorry, the alpha must lie within (0,1)") #Assign Row and Column Labelss if ( (is.null(rownames(X))) && (is.null(colnames(X))) ) { rownames(X) <- c("Risk Present", "Risk Absent") colnames(X) <- c("Disease Present (Cases)", "Disease Absent (Controls)"); } #Initialize Parameters r <- NULL; r$digits <- digits; r$X <- X; r$alpha <- alpha; #For notation, r1 = sum of first row, etc. a <- X[1,1]; b <- X[1,2]; c <- X[2,1]; d <- X[2,2]; r1 <- a + b; r2 <- c + d; c1 <- a + c; c2 <- b+d; T1 <- r1 + r2; #Chi-Squared Test (With Continuity Correction) r$Sy <- T1*((abs(a*d - b*c) - T1/2)^2)/(c1*c2*r1*r2); r$Sy.p.value <- 1- pchisq(r$Sy,1); #Fisher's Exact r$Fisher.p.value <- fisher.test(X)$p.value; #Odds Ratio and Confidence Limits r$OR <- (a*d)/(b*c) r$OR.CIL <- exp(log(r$OR) - qnorm(1 - alpha/2) * sqrt(1/a + 1/b + 1/c + 1/d)); r$OR.CIU <- exp(log(r$OR) + qnorm(1 - alpha/2) * sqrt(1/a + 1/b + 1/c + 1/d)); #Cohort Study Info r$p1Co <- a/r1; r$p2Co <- c/r2; r$rdCo <- r$p1Co - r$p2Co; r$rdCo.CIL <- r$rdCo - (1/r1 + 1/r2)/2 - qnorm(1 - alpha/2) * sqrt(r$p1Co*(1-r$p1Co)/r1 + r$p2Co*(1-r$p2Co)/r2); r$rdCo.CIU <- r$rdCo + (1/r1 + 1/r2)/2 + qnorm(1 - alpha/2) * sqrt(r$p1Co*(1-r$p1Co)/r1 + r$p2Co*(1-r$p2Co)/r2); #Relative Risk and CI r$RR <- r$p1Co/r$p2Co; r$RR.CIL <- exp( log(r$RR) - qnorm(1 - alpha/2) * sqrt( b/(a*(a+b)) + d/(c*(c+d)) )); r$RR.CIU <- exp( log(r$RR) + qnorm(1 - alpha/2) * sqrt( b/(a*(a+b)) + d/(c*(c+d)) )); #Case Control Study risk difference r$p1CC <- a/c1; r$p2CC <- b/c2; r$rdCC <- r$p1CC - r$p2CC; r$rdCC.CIL <- r$rdCC - (1/c1 + 1/c2)/2 - qnorm(1 - alpha/2) * sqrt(r$p1CC*(1-r$p1CC)/r1 + r$p2CC*(1-r$p2CC)/r2); r$rdCC.CIU <- r$rdCC + (1/c1 + 1/c2)/2 + qnorm(1 - alpha/2) * sqrt(r$p1CC*(1-r$p1CC)/r1 + r$p2CC*(1-r$p2CC)/r2); class(r) <- "epi2x2"; return(r); } #Print Method print.epi2x2 <- function(x, ...) { cat("Epidemiological 2x2 Table Analysis", "\n \n"); cat("Input Matrix: \n") print(x$X) cat("\n", "Pearson Chi-Squared Statistic (Includes Yates' Continuity Correction): ", round(x$Sy, digits=x$digits), "\n", sep="") cat("Associated p.value for H0: There is no association between exposure and outcome vs. HA: There is an association : ", round(x$Sy.p.value, digits=x$digits), "\n", sep="") cat("p.value using Fisher's Exact Test: ", round(x$Fisher.p.value, digits=x$digits), "\n \n", sep=""); cat("Estimate of Odds Ratio: ", round(x$OR, digits=x$digits), "\n", sep="") cat(100*(1-x$alpha), "% Confidence Limits for true Odds Ratio are: [", round(x$OR.CIL,digits=x$digits), ", ", round(x$OR.CIU,digits=x$digits),"]", "\n", sep=""); } #Summary Method summary.epi2x2 <- function(object, ...) { cat("Epidemiological 2x2 Table Analysis", "\n \n"); cat("Input Matrix: \n") print(object$X) cat("\n", "Pearson Chi-Squared Statistic (Includes Yates' Continuity Correction): ", round(object$Sy, digits=object$digits), "\n", sep="") cat("Associated p.value for H0: There is no association between exposure and outcome vs. HA: There is an association : ", round(object$Sy.p.value, digits=object$digits), "\n", sep="") cat("p.value using Fisher's Exact Test (1 DF) : ", round(object$Fisher.p.value, digits=object$digits), "\n \n", sep=""); cat("Estimate of Odds Ratio: ", round(object$OR, digits=object$digits), "\n", sep="") cat(100*(1-object$alpha), "% Confidence Limits for true Odds Ratio are: [", round(object$OR.CIL,digits=object$digits), ", ", round(object$OR.CIU,digits=object$digits),"]", "\n \n", sep=""); cat("Estimate of Relative Risk (Cohort, Col1): ", round(object$RR, digits=object$digits), "\n", sep="") cat(100*(1-object$alpha), "% Confidence Limits for true Relative Risk are: [", round(object$RR.CIL,digits=object$digits), ", ", round(object$RR.CIU,digits=object$digits),"]", "\n \n", sep=""); cat("Estimate of Risk Difference (p1 - p2) in Cohort Studies: ", round(object$rdCo, digits=object$digits), "\n", sep="") cat(100*(1-object$alpha), "% Confidence Limits for Risk Difference: [", round(object$rdCo.CIL,digits=object$digits), ", ", round(object$rdCo.CIU,digits=object$digits),"]", "\n \n", sep=""); cat("Estimate of Risk Difference (p1 - p2) in Case Control Studies: ", round(object$rdCC, digits=object$digits), "\n", sep="") cat(100*(1-object$alpha), "% Confidence Limits for Risk Difference: [", round(object$rdCC.CIL,digits=object$digits), ", ", round(object$rdCC.CIU,digits=object$digits),"]", "\n \n", sep=""); cat("Note: Above Confidence Intervals employ a continuity correction.", "\n") }epibasix/R/sensSpec.R0000755000176200001440000000731411150621070014166 0ustar liggesuserssensSpec <- function(X, alpha=0.05, CL=TRUE, digits=3) { #Error Checking if ((nrow(X) != ncol(X)) || (nrow(X) != 2)) stop("Sorry, 'X' must be a 2x2 Matrix...") if ((alpha >= 1) || (alpha <= 0)) stop("Sorry, the alpha must lie within (0,1)") #Assign row and column names if ( (is.null(rownames(X))) && (is.null(colnames(X))) ) { rownames(X) <- c("Reported A", "Reported B") colnames(X) <- c("Gold Standard A", "Gold Standard B"); } #Object Initialization results <- NULL; results$X <- X; results$digits <- digits; results$alpha <- alpha; results$CL <- CL; #For notation, r1 = sum of first row, c1 = sum of first col. etc. a <- X[1,1]; b <- X[1,2]; c <- X[2,1]; d <- X[2,2]; r1 <- a + b; r2 <- c + d; c1 <- a + c; c2 <- b+d; T1 <- r1 + r2; #Calculate point estimates... results$sens <- a/c1; results$spec <- d/c2; results$YoudenJ <- results$sens + results$spec - 1; results$PA <- (a +d)/(T1); #Compute Confidence Limits if required if (CL) { results$sens.s <- sqrt(((results$sens*(1 - results$sens))/c1)) results$sens.CIL <- results$sens - qnorm(1 - alpha/2)*results$sens.s results$sens.CIU <- results$sens + qnorm(1 - alpha/2)*results$sens.s results$spec.s <- sqrt(((results$spec*(1 - results$spec))/c2)) results$spec.CIL <- results$spec - qnorm(1 - alpha/2)*results$spec.s results$spec.CIU <- results$spec + qnorm(1 - alpha/2)*results$spec.s results$PA.s <- sqrt(((results$PA*(1 - results$PA))/T1)) results$PA.CIL <- results$PA - qnorm(1 - alpha/2)*results$PA.s results$PA.CIU <- results$PA + qnorm(1 - alpha/2)*results$PA.s results$YoudenJ.s <- sqrt( ((results$sens*(1 - results$sens))/c1) + ((results$spec*(1 - results$spec))/c2) ); results$YoudenJ.CIL <- results$YoudenJ - qnorm(1 - alpha/2)*results$YoudenJ.s results$YoudenJ.CIU <- results$YoudenJ + qnorm(1 - alpha/2)*results$YoudenJ.s } class(results) <- "sensSpec"; return(results); } #Print Method print.sensSpec <- function(x, ...) { cat("\n", "Simple Sensitivity and Specitivity Output", "\n \n"); cat("Input Matrix: \n") print(x$X) cat("\n", "The sample of sensitivity is: ", 100* round(x$sens,digits=x$digits), "% \n", sep="") cat("\n", "The sample of specificity is: ", 100* round(x$spec,digits=x$digits), "% \n", sep="") } #Summary Method summary.sensSpec <- function(object, ...) { cat("\n", "Detailed Sensitivity and Specitivity Output", "\n \n"); cat("Input Matrix: \n") print(object$X) cat("\n", "The sample sensitivity is: ", 100* round(object$sens,digits=object$digits), "% \n", sep="") if (object$CL){ cat(100*(1-object$alpha), "% Confidence Limits for true sensitivity are: [", 100* round(object$sens.CIL,digits=object$digits), ", ", 100* round(object$sens.CIU,digits=object$digits),"]", "\n", sep=""); } cat("\n", "The sample of specificity is: ", 100* round(object$spec,digits=object$digits), "% \n", sep="") if (object$CL){ cat(100*(1-object$alpha), "% Confidence Limits for true specificity are: [",100* round(object$spec.CIL,digits=object$digits), ", ", 100* round(object$spec.CIU,digits=object$digits),"]", "\n", sep=""); } cat("\n", "The sample value of Youden's J is: ", 100*round(object$YoudenJ,digits=object$digits), "\n", sep="") if (object$CL){ cat(100*(1-object$alpha), "% Confidence Limits for Youden's J are: [", 100*round(object$YoudenJ.CIL,digits=object$digits), ", ", 100*round(object$YoudenJ.CIU,digits=object$digits),"]", "\n", sep=""); } cat("\n","Sample value for Percent Agreement (PA) is: ", 100*round(object$PA,digits=object$digits), "% \n", sep="") if (object$CL){ cat(100*(1-object$alpha), "% Confidence Limits for PA are: [", 100*round(object$PA.CIL,digits=object$digits), ", ", 100*round(object$PA.CIU,digits=object$digits),"]", "\n \n", sep=""); } }epibasix/R/mcNemar.R0000755000176200001440000000642111150621000013754 0ustar liggesusersmcNemar <- function(X, alpha = 0.05, force=FALSE, digits=3) { #Error Checking if (nrow(X) != ncol(X)) stop("Sorry, 'X' must be a 2x2 Matrix...") #For notation... a <- X[1,1]; b <- X[1,2]; c <- X[2,1]; d <- X[2,2] n <- sum(X); if ((alpha >= 1) || (alpha <= 0)) stop("Sorry, the alpha must lie within (0,1)") #To proceed with function with insufficient data, set force=TRUE if (!force) { if (b+c <= 30) stop("The number of discordant pairs, must be greater than 30 to ensure validity.") } #Names for Rows and Columns if ( (is.null(rownames(X))) && (is.null(colnames(X))) ) { colnames(X) <- c("Exposed Person: Disease Present", "Exposed Person: Disease Absent") rownames(X) <- c("Control Person: Disease Present", "Control Person: Disease Absent"); } #Initialize Parameters result <- NULL; result$X <- X; result$alpha <- alpha; result$digits <- digits; #McNemar's Odds Ratio result$ORMc <- b/c; p <- b/(b+c); pL <- p - 1/(2*(b+c)) - qnorm(1-alpha/2)*sqrt((b*c)/((b+c)^3)); pU <- p + 1/(2*(b+c)) + qnorm(1-alpha/2)*sqrt((b*c)/((b+c)^3)); #OR Confidence Limits result$ORMc.CIL <- pL/(1-pL); result$ORMc.CIU <- pU/(1-pU); #Risk Difference and CI result$rd <- (b - c)/n; result$rd.CIL <- result$rd - (1/n) - qnorm(1-alpha/2)*(sqrt((a + d)*(b+c)+4*b*c)/(n*sqrt(n))); result$rd.CIU <- result$rd + (1/n) + qnorm(1-alpha/2)*(sqrt((a + d)*(b+c)+4*b*c)/(n*sqrt(n))); #McNemarStat, with Continuity Correction result$XMc <- ((abs(b-c) -1)^2)/(b+c); result$XMc.p.value <- 1 - pchisq(result$XMc,1); class(result) <- "mcNemar"; return(result) } #Print Method print.mcNemar <- function(x, ...) { cat("\n","Matched Pairs Analysis: McNemar's Chi^2 Statistic and Odds Ratio", "\n \n", sep="") cat("McNemar's Chi^2 Statistic (corrected for continuity) = ", round(x$XMc, digits=x$digits), " which has a p-value of: ", round(x$XMc.p.value, digits=x$digits), "\n \n",sep="") cat("McNemar's Odds Ratio (b/c): ", round(x$ORMc, digits=x$digits), "\n", sep="") cat(100*(1-x$alpha), "% Confidence Limits for the OR are: [", round(x$ORMc.CIL,digits=x$digits), ", ", round(x$ORMc.CIU,digits=x$digits),"]", "\n", sep=""); } #Summary Method summary.mcNemar <- function(object, ...) { cat("\n", "Matched Pairs Analysis: McNemar's Statistic and Odds Ratio (Detailed Summary):", "\n \n", sep="") print(object$X); cat("\n"); cat("Entries in above matrix correspond to number of pairs.", "\n \n") cat("McNemar's Chi^2 Statistic (corrected for continuity) = ", round(object$XMc, digits=object$digits), " which has a p-value of: ", round(object$XMc.p.value, digits=object$digits), "\n",sep="") cat("Note: The p.value for McNemar's Test corresponds to the hypothesis test: H0: OR = 1 vs. HA: OR != 1", "\n", sep="") cat("McNemar's Odds Ratio (b/c): ", round(object$ORMc, digits=object$digits), "\n", sep="") cat(100*(1-object$alpha), "% Confidence Limits for the OR are: [", round(object$ORMc.CIL,digits=object$digits), ", ", round(object$ORMc.CIU,digits=object$digits),"]", "\n", sep=""); cat("The risk difference is: ", round(object$rd, digits=object$digits), "\n", sep="") cat(100*(1-object$alpha), "% Confidence Limits for the rd are: [", round(object$rd.CIL,digits=object$digits), ", ", round(object$rd.CIU,digits=object$digits),"]", "\n", sep=""); }epibasix/R/univar.R0000755000176200001440000000532411150621112013703 0ustar liggesusersunivar <- function(X,alpha=0.05, mu0 = 0, shapiro=FALSE, digits=3) { #Error Checking if (!is.vector(X)) stop("Sorry, X must be a vector..."); if ((alpha >= 1) || (alpha <= 0)) stop("Sorry, the alpha must lie within (0,1)"); #Initialize parameters Result <- NULL; Result$mu0 <- mu0; Result$n <- length(X); Result$alpha <- alpha; Result$digits <- digits; Result$shapiro <- shapiro; #Compute basic statistics Result$mean <- mean(X); Result$median <- median(X); Result$min <- min(X); Result$max <- max(X); Result$s <- sd(X); Result$var <- var(X) Result$CIL <- Result$mean - qt(1-alpha/2,length(X)-1)*Result$s/sqrt(length(X)); Result$CIU <- Result$mean + qt(1-alpha/2,length(X)-1)*Result$s/sqrt(length(X)); #Hypothesis test for mu Result$test <- sqrt(length(X))*abs(Result$mean - mu0)/Result$s; Result$p.value <- 2*pt(Result$test, Result$n - 1, lower.tail=FALSE); #Shapiro test if required !(shapiro) { Result$shapiro.statistic <- shapiro.test(X)$statistic; Result$shapiro.p.value <- shapiro.test(X)$p.value; } class(Result) <- "univar"; return(Result); } #Print Method print.univar <- function(x, ...) { cat("\n","Univariate Summary", "\n \n", sep="") cat("Sample Size: ", x$n, "\n", sep="" ) cat("Sample Mean:", round(x$mean,digits=x$digits), "\n", sep=" ") cat("Sample Median:", round(x$median,digits=x$digits), "\n", sep=" ") cat("Sample Standard Deviation:", round(x$s,digits=x$digits), "\n", sep=" ") } #Summary Method summary.univar <- function(object, ...) { cat("\n", "Basic Univariate Output", "\n \n", sep="") cat("Sample Size: ", object$n, "\n", sep="" ) cat("Sample Mean:", round(object$mean,digits=object$digits), "\n", sep=" ") cat("Sample Median:", round(object$median,digits=object$digits), "\n", sep=" ") cat("The sample values range from: ", round(object$min, digits=object$digits), " through ", round(object$max, digits=object$digits), "\n", sep=""); cat("Sample Standard Deviation:", round(object$s,digits=object$digits), "\n", sep=" ") cat("Sample Variance:", round(object$var,digits=object$digits), "\n \n ", sep=" ") cat(100*(1-object$alpha), "% Confidence Limits for mu are: [", round(object$CIL,digits=object$digits), ", ", round(object$CIU,digits=object$digits),"]", "\n", sep=""); cat("p-value for the Test of H0: mu = ", object$mu0, " vs. HA: mu != ", object$mu0, " is ", round(object$p.value,digits=object$digits), "\n \n", sep=""); cat("Note: P-Values and Confidence Intervals for mu assume an approximate normal distribution!", "\n", sep="") if (object$shapiro) cat("Shapiro-Wilks Statistic: ", round(object$shapiro.statistic, digits=object$digits), " with an approximate p-value of: ", round(object$shapiro.p.value,digits=object$digits), "\n", sep=""); }epibasix/R/epiKappa.R0000755000176200001440000000651411202537164014146 0ustar liggesusersepiKappa <- function(C, alpha=0.05, k0=0.4, digits=3) { #Error Checking if (nrow(C) != ncol(C)) stop("Sorry, this function Requires a Square Matrix of Counts of Agreement or Proportions of Agreement") if ((alpha >= 1) || (alpha <= 0)) stop("Sorry, the alpha must lie within (0,1)") #Append Row/Col classifications if ( (is.null(rownames(C))) && (is.null(colnames(C))) ) { cN <- NULL; rN <- NULL; for (i in 1:nrow(C)) { cN <- append(cN, paste("Rater I: Type ", i, sep="")); rN <- append(rN, paste("Rater II: Type ", i, sep="")); } colnames(C) <- cN rownames(C) <- rN } #Initialize Objects r <- NULL; r$k0 <- k0; r$digits <- digits; r$alpha <- alpha; r$Data <- C; T1 <- sum(C); X <- C/T1; r$p0 <- sum(diag(X)); pe <- rep(NA, nrow(X)); for (i in 1:nrow(X)) { pe[i] <- sum(X[,i])*sum(X[i,]); } r$pe <- sum(pe) #Calculate Kappa using pe r$kappa <- (r$p0 - r$pe)/(1 - r$pe); #Strings for Fleiss Agreement Statement if (r$kappa <= 0.4) { r$Fleiss <- "poor"; } if ( (0.4 < r$kappa) && (r$kappa <= 0.75) ) { r$Fleiss <- "fair to good"; } if ( (0.75 < r$kappa) && (r$kappa <= 1.0) ) { r$Fleiss <- "excellent"; } #Placeholders to calculate variance using standard formulae. AH <- rep(NA, nrow(X)); BH <- matrix(0, nrow(X), nrow(X)); AC <- rep(NA, nrow(X)); BC <- matrix(0, nrow(X), nrow(X)); for (i in 1:nrow(X)) { AH[i] <- X[i,i]*(( 1 - (sum(X[i,]) + sum(X[,i])) *(1-r$k0)))^2; AC[i] <- X[i,i]*(( 1 - (sum(X[i,]) + sum(X[,i])) *(1-r$kappa)))^2; } for (i in 1:nrow(X)) { for (j in 1:nrow(X)) { if (i != j) { BH[i,j] <- (1 - r$k0)^2 * X[i,j]*(sum(X[j,]) + sum(X[,i])); BC[i,j] <- (1 - r$kappa)^2 * X[i,j]*(sum(X[j,]) + sum(X[,i])); } } } AH <- sum(AH); AC <- sum(AC); BH <- sum(BH); BC <- sum(BC); CH <- (r$k0 -r$pe*(1-r$k0))^2; CC <- (r$kappa -r$pe*(1-r$kappa))^2; #Standard errors for hypothesis tests and CI's r$seH <- sqrt( (AH + BH -CH)/T1 )/(1-r$pe); r$seC <- sqrt( (AC + BC -CC)/T1 )/(1-r$pe); #Z Test for kappa r$Z <- (r$kappa - r$k0)/r$seH; r$p.value <- 1 - pnorm(r$Z); #CI's for kappa. r$CIL <- r$kappa - qnorm(1 - alpha/2) * r$seC; r$CIU <- r$kappa + qnorm(1 - alpha/2)* r$seC; class(r) <- "epiKappa"; return(r); } #summary method summary.epiKappa <- function(object, ...) { cat("Kappa Analysis of Agreement", "\n \n") print(object$Data); cat("\n"); cat("Cohen's Kappa is: ", round(object$kappa, digits = object$digits), "\n") cat("According to Fleiss (1981), the point estimate of kappa suggests ", object$Fleiss, " agreement.", "\n \n",sep=""); cat(100*(1-object$alpha), "% Confidence Limits for the true Kappa Statistic are: [", round(object$CIL,digits=object$digits), ", ", round(object$CIU,digits=object$digits),"]", "\n \n", sep=""); cat("Z Test for H0: kappa = ", object$k0, " vs. HA: kappa >= ", object$k0, " is ", round(object$Z,digits=object$digits), " with a p.value of ", round(object$p.value, digits=object$digits), "\n \n", sep=""); cat("The associated standard error under H0 is: ", round(object$seH, digits=object$digits), "\n", sep="") } #Print method print.epiKappa <- function(x, ...) { cat("Kappa Analysis of Agreement", "\n \n") cat("Cohen's Kappa is: ", round(x$kappa, digits = x$digits), "\n") cat("According to Fleiss (1981), the point estimate of kappa suggests ", x$Fleiss, " agreement. \n", sep=""); }epibasix/R/corXY.R0000755000176200001440000000457011150620624013454 0ustar liggesuserscorXY <- function(X,Y, alpha=0.05, rho0 = 0, HA="not.equal", digits=3) { #Check for errors if (length(X) != length(Y)) stop("Sorry, this function Requires Two Vectors of the Same Length") if ((alpha >= 1) || (alpha <= 0)) stop("Sorry, the alpha must lie within (0,1)") #Initialize object and parameters result <- NULL; result$digits <- digits; result$alpha <- alpha; result$rho0 <- rho0; result$HA = HA; result$rho <- cor(X,Y); result$n <- length(X); #Fisher's Z Transform and Hypothesis Testing Section result$Z <- (1/2)*log((1+result$rho)/(1-result$rho)); result$Z0 <- (1/2)*log((1+rho0)/(1-rho0)); if (HA == "not.equal") { result$Test <- abs(result$Z - result$Z0)*sqrt(result$n-3); result$p.value <- 2*(1 - pnorm(result$Test)); } if (HA == "less.than") { result$Test <- abs(result$Z - result$Z0)*sqrt(result$n-3); result$p.value <- pnorm(result$Test); } if (HA == "greater.than") { result$Test <- abs(result$Z - result$Z0)*sqrt(result$n-3); result$p.value <- (1 - pnorm(result$Test)); } #Compute Confidence Intervals L <- result$Z - qnorm(1 - alpha/2)/sqrt(result$n-3); U <- result$Z + qnorm(1 - alpha/2)/sqrt(result$n-3); result$CIL <- (exp(2*L) -1)/(exp(2*L) + 1); result$CIU <- (exp(2*U) -1)/(exp(2*U) + 1); class(result) <- "corXY"; return(result); } #Print Method print.corXY <- function(x, ...) { cat("\n","Correlation Summary", "\n \n", sep="") cat("Sample Size: ", x$n, "\n", sep="" ) cat("Sample Correlation: ", round(x$rho, digits=x$digits), "\n", sep="") cat(100*(1-x$alpha), "% Confidence Limits for rho are (using Fisher's Z Transformation) : [", round(x$CIL,digits=x$digits), ", ", round(x$CIU,digits=x$digits),"]", "\n", sep=""); } #Summary Method summary.corXY <- function(object, ...) { cat("\n","Correlation Details", "\n \n", sep="") cat("Sample Size: ", object$n, "\n", sep="" ) cat("Sample Correlation: ", round(object$rho, digits=object$digits), "\n", sep="") cat(100*(1-object$alpha), "% Confidence Limits for rho are (using Fisher's Z Transformation) : [", round(object$CIL,digits=object$digits), ", ", round(object$CIU,digits=object$digits),"]", "\n", sep=""); cat("Z statistic for H0: rho = ", object$rho0, " vs. HA: rho ", object$HA, " to ", object$rho0, ": ", round(object$Test, digits=object$digits), " , which has a p.value of ", round(object$p.value, digits=object$digits), "\n", sep=""); }epibasix/R/n4props.R0000755000176200001440000000357111150621046014014 0ustar liggesusersn4props <- function(pe,pc, alpha=0.05, power=0.8, AR=1, two.tailed=TRUE, digits=3) { #Error Checking if ((pe >= 1) || (pe <= 0) || (pc <= 0) || (pe >= 1)) stop("Sorry, the prior proportions must lie within (0,1)") if ((alpha >= 1) || (alpha <= 0) || (power <= 0) || (power >= 1)) stop("Sorry, the alpha and power must lie within (0,1)") if (AR <=0) stop("Sorry, the specified value of the Allocation Ratio (AR) must be strictly positive...") #Initialize Parameters r <- NULL; r$pe <- pe; r$pc <- pc; r$digits <- digits; r$alpha <- alpha; r$power <- power; r$AR <- AR; r$two.tailed <- two.tailed; #One or two-tailed tests if (two.tailed) { r$n <- (qnorm(1 - alpha/2) + qnorm(power))^2*(pe*(1-pe) + pc*(1-pc))/(pe - pc)^2; r$nE = (1/2)*r$n*(1 + (1/AR)); r$nC = (1/2)*r$n*(1 + AR); } else { r$n <- (qnorm(1 - alpha) + qnorm(power))^2*(pe*(1-pe) + pc*(1-pc))/(pe - pc)^2; r$nE = (1/2)*r$n*(1 + (1/AR)); r$nC = (1/2)*r$n*(1 + AR); } class(r) <- "n4props"; return(r); } #Print Method print.n4props <- function(x, ...) { cat("The required sample size is a minimum of ", ceiling(x$nE), " individuals in the Experimental Group \n", sep="") cat(" and a minimum of ", ceiling(x$nC), " individuals in the Control Group. \n", sep="") } #Summary Method summary.n4props <- function(object, ...) { cat("Sample Size Calculation for Binary Outcomes", "\n \n") cat("Assuming:", "\n") cat("Proportion with Outcome in Experimental Group: ", object$pe, "\n") cat("Proportion with Outcome in Control Group: ", object$pc, "\n") cat("Type I Error Rate (alpha) = ", object$alpha, " and Power = ", object$power, "\n \n",sep="") cat("The required sample size is a minimum of ", ceiling(object$nE), " individuals in the Experimental Group \n", sep="") cat(" and a minimum of ", ceiling(object$nC), " individuals in the Control Group. \n", sep="") }epibasix/MD50000644000176200001440000000202413374642443012376 0ustar liggesusersc35df699adf1bf268ecf9b36ea65fba5 *DESCRIPTION 6a5469a1d7d606b18d75fd4dd1beeb0d *NAMESPACE 623240ba2b1e1dc854889ff434ebed5d *R/corXY.R 09b25c367148357f56f10447eb04f36e *R/diffDetect.R df0f1a480cdf5f41465e1a80b30b4e39 *R/epi2x2.R 2d83d2ba460de7e69752c68a40f55bdd *R/epiKappa.R b91e4626369af06cbd56790316d605ec *R/epiTTest.R d535bdddaf7c8e477d35171697c14bff *R/mcNemar.R 110aa560d6021f3cc79a1e36bda81649 *R/n4means.R defdc6e3cf1eb5706395639192ffc8d2 *R/n4props.R 62105be3bf35ce5f4c976366efebbf91 *R/sensSpec.R b2699b9f5fb0018e49ea99582b904e9d *R/univar.R db3f043bd2560b9527262678d271b574 *man/corXY.Rd 9a3b4119807127fafb355274ff1466cd *man/diffDetect.Rd 34d95e7219ceabca84a23d7e3f6d6cdd *man/epi2x2.Rd 5461499641446bdecc2740f082a3bfde *man/epiKappa.Rd f3da9ada10eed7b6b95bfcea78fa57e5 *man/epiTTest.Rd 08b07df4fd8a46d601a0f0c6cd0ae530 *man/mcNemar.Rd b3e7da0ed26c6bfa00f0b4901edb848d *man/n4means.Rd 3a4a305b26809613fdfbd8ebbe7c63ef *man/n4props.Rd 013a46124af28f7e6175d668fc1e0dab *man/sensSpec.Rd 7543f8cd44940aa23bb258b42e1eb17b *man/univar.Rd epibasix/DESCRIPTION0000755000176200001440000000173513374642443013607 0ustar liggesusersPackage: epibasix Version: 1.5 Date: 2018-11-19 Title: Elementary Epidemiological Functions for Epidemiology and Biostatistics Author: Michael A Rotondi Maintainer: Michael A Rotondi Depends: R (>= 2.01) Description: Contains elementary tools for analysis of common epidemiological problems, ranging from sample size estimation, through 2x2 contingency table analysis and basic measures of agreement (kappa, sensitivity/specificity). Appropriate print and summary statements are also written to facilitate interpretation wherever possible. Source code is commented throughout to facilitate modification. The target audience includes advanced undergraduate and graduate students in epidemiology or biostatistics courses, and clinical researchers. License: GPL (>= 2) NeedsCompilation: no Packaged: 2018-11-19 21:25:51 UTC; mrotondi Repository: CRAN Date/Publication: 2018-11-19 23:20:03 UTC epibasix/man/0000755000176200001440000000000013374624266012646 5ustar liggesusersepibasix/man/n4props.Rd0000755000176200001440000000532213374620534014541 0ustar liggesusers\name{n4props} \alias{n4props} \alias{print.n4props} \alias{summary.n4props} \title{Number of Subjects Required for a Randomized Trial with Binary Outcomes} \description{ This function provides detailed sample size estimation information to determine the number of subjects that must be enrolled in a randomized trial with a binary outcome.} \usage{n4props(pe, pc, alpha=0.05, power = 0.80, AR=1, two.tailed=TRUE, digits=3)} \arguments{ \item{pe}{The anticipated proportion of individuals in the experimental group with the outcome.} \item{pc}{The anticipated proportion of individuals in the control group with the outcome.} \item{AR}{The Allocation Ratio: One implies an equal number of subjects per treatment and control group (maximum efficiency), > 1, implies more subjects will be enrolled in the control group (e.g. in the case of costly intervention), < 1 implies more in the tretment group (rarely used).} \item{alpha}{The desired Type I Error Rate} \item{power}{The desired level of power, recall power = 1 - Type II Error.} \item{two.tailed}{Logical, If TRUE calculations are based on a two-tailed Type I error, if FALSE, a one-sided calculation is performed.} \item{digits}{Number of Digits to round calculations} } \details{ This function provides detailed information, similar to PROC POWER in SAS, but with less functionality and more concise output. It is used for sample size estimation in a randomized trial where the response is binary. A simple example may include whether an individual dies from a heart attack. In epidemiological terms, pe and pc can be thought of as the expected prevalence of the outcome in the experimental and control group. } \value{ \item{nE}{The minimum number of subjects required in the Experimental group.} \item{nC}{The minimum number of subjects required in the Control group.} \item{pe}{The anticipated proportion of individuals in the experimental group with the outcome.} \item{pc}{The anticipated proportion of individuals in the control group with the outcome.} \item{alpha}{The desired Type I Error Rate} \item{power}{The desired level of power, recall power = 1 - Type II Error.} \item{AR}{The Allocation Ratio} } \references{ Matthews JNS. Introduction to Randomized Controlled Clinical Trials (2nd Ed.) Chapman & Hall: New York, 2006. } \author{Michael Rotondi, \email{mrotondi@yorku.ca}} \seealso{\code{\link{n4means}}} \examples{ \dontrun{Suppose a new drug is thought to reduce heart attack mortality from 0.10 to 0.03. Calculate the required number of subjects that must be enrolled in a study to detect this difference with alpha = 0.05 and power = 0.80.} n4props(0.03, 0.10, AR=1, alpha=0.05, power=0.80); } \keyword{design} epibasix/man/epiKappa.Rd0000755000176200001440000000445312463727270014675 0ustar liggesusers\name{epiKappa} \alias{epiKappa} \alias{print.epiKappa} \alias{summary.epiKappa} \title{Computation of the Kappa Statistic for Agreement Between Two Raters} \description{ Computes the Kappa Statistic for agreement between Two Raters, performs Hypothesis tests and calculates Confidence Intervals. } \usage{epiKappa(C, alpha=0.05, k0=0.4, digits=3)} \arguments{ \item{C}{An nxn classification matrix or matrix of proportions.} \item{k0}{The Null hypothesis, kappa0 = k0} \item{alpha}{The desired Type I Error Rate for Hypothesis Tests and Confidence Intervals} \item{digits}{Number of Digits to round calculations} } \details{ The Kappa statistic is used to measure agreement between two raters. For simplicity, consider the case where each rater can classify an object as Type I, or Type II. Then, the diagonal elements of a 2x2 matrix are the agreeing elements, that is where both raters classify an object as Type I or Type II. The discordant observations are on the off-diagonal. Note that the alternative hypothesis is always greater then, as we are interested in whether kappa exceeds a certain threshold, such as 0.4, for Fair agreement. } \value{ \item{kappa}{The computation of the kappa statistic.} \item{seh}{The standard error computed under H0} \item{seC}{The standard error as computed for Confidence Intervals} \item{CIL}{Lower Confidence Limit for \eqn{\kappa}{kappa}} \item{CIU}{Upper Confidence Limit for \eqn{\kappa}{kappa}} \item{Z}{Hypothesis Test Statistic, \eqn{\kappa = K0}{kappa = K0} = K0 vs. \eqn{\kappa > K0}{kappa > K0}} \item{p.value}{P-Value for hypothesis test} \item{Data}{Returns the original matrix of agreement.} \item{k0}{The Null hypothesis, kappa = k0} \item{alpha}{The desired Type I Error Rate for Hypothesis Tests and Confidence Intervals} \item{digits}{Number of Digits to round calculations} } \references{ Szklo M and Nieto FJ. Epidemiology: Beyond the Basics, Jones and Bartlett: Boston, 2007. Fleiss J. Statistical Methods for Rates and Proportions, 2nd ed. New York: John Wiley and Sons; 1981. } \author{Michael Rotondi, \email{mrotondi@yorku.ca}} \seealso{\code{\link{sensSpec}}} \examples{ X <- cbind(c(28,5), c(4,61)); summary(epiKappa(X, alpha=0.05, k0 = 0.6)); } \keyword{design} \keyword{multivariate} \keyword{htest}epibasix/man/corXY.Rd0000755000176200001440000000415712463727222014205 0ustar liggesusers\name{corXY} \alias{corXY} \alias{summary.corXY} \alias{print.corXY} \title{Correlation of Two Vectors} \description{ This function displays the simple correlation of two vectors of equal length, as well as providing confidence limits and hypothesis tests.} \usage{corXY(X, Y, alpha=0.05, rho0 = 0, HA="not.equal", digits=3)} \arguments{ \item{X}{A Vector of the same length as Y} \item{Y}{A Vector of the same length as X, This function requires the input of Vectors} \item{alpha}{The Type I error rate for Hypothesis Tests and Confidence Intervals} \item{rho0}{The Null Hypothesis for Hypothesis Tests} \item{HA}{The alternative hypothesis can be one of "less.than", "greater.than", or "not.equal"} \item{digits}{The number of digits to round results} } \details{This function provides the required information, such as the Pearson correlation Hypothesis Tests and confidence intervals, while providing suitable detail in the and print statements for epidemiologists to understand the information at hand.} \value{ \item{rho}{The Sample Pearson Correlation, as calculated in the cor function.} \item{n}{The sample size.} \item{Test}{The Test Statistic for the desired hypothesis test based on Fisher's Transformation.} \item{p.Value}{The p-value for the Hypothesis Test.} \item{CIL}{The lower bound of the constructed confidence interval for \eqn{\rho}{rho}, again based on Fisher's Z Transformation.} \item{CIU}{The Upper bound of the constructed confidence interval for \eqn{\rho}{rho}, again based on Fisher's Z Transformation.} \item{alpha}{The desired Type I Error Rate} \item{rho0}{The Null Hypothesis} \item{HA}{The supplied Alternative Hypothesis} } \references{ Casella G and Berger RL. Statistical Inference (2nd Ed.) Duxbury: New York, 2002. Koepsell TD and Weiss NS. Epidemiologic Methods. Oxford University Press: New York, 2003. } \author{Michael Rotondi, \email{mrotondi@yorku.ca}} \examples{ \dontrun{Suppose we want to test whether two randomly generated normal vectors are uncorrelated} x <- rnorm(100); y <- rnorm(100); corXY(x,y); } \keyword{multivariate} \keyword{htest} epibasix/man/mcNemar.Rd0000755000176200001440000000433512463727316014525 0ustar liggesusers\name{mcNemar} \alias{mcNemar} \alias{print.mcNemar} \alias{summary.mcNemar} \title{Pair-Matched Analysis Tool} \description{ This function performs elemenentary pair-matched analysis using McNemar's test and computing risk differences. } \usage{mcNemar(X, alpha= 0.05, force=FALSE, digits=3)} \arguments{ \item{X}{A 2x2 matrix, with disease status (Yes/No) for the exposed individual in the columns and disease status (Yes/No) for the control individuals in the rows. Note that for a matched-pair analysis, each entry corresponds to a pair of subjects.} \item{alpha}{The desired Type I Error Rate for Hypothesis Tests and Confidence Intervals} \item{force}{Logical: McNemar's test is typically valid when the number of discordant pairs exceeds 30. The function may be forced to work, without regards to this concern with FORCE=TRUE.} \item{digits}{Number of Digits to round calculations} } \details{ McNemar's OR is computed as b/c. While standard errors are computed using a transformation. The risk difference is computed as \eqn{(b - c)/n}{(b-c)/n}. Note that this technique can be used for cohort studies as well as matched trials. } \value{ \item{X}{The original input matrix.} \item{ORMc}{McNemar's Odds Ratio} \item{ORMC.CIL}{Lower Confidence Limit for McNemar's OR} \item{ORMC.CIU}{Upper Confidence Limit for McNemar's OR} \item{rd}{Point Estimate of the risk difference} \item{rd.CIL}{Lower Confidence Limit for the risk difference} \item{rd.CIU}{Upper Confidence Limit for the risk difference} \item{XMc}{Value for McNemar's Chi-squared statistic}. \item{XMc.p.Value}{P-value for the hypothesis test of no association.} \item{alpha}{The desired Type I Error Rate for Hypothesis Tests and Confidence Intervals} \item{digits}{Number of Digits to round calculations} } \references{ Szklo M and Nieto FJ. Epidemiology: Beyond the Basics, Jones and Bartlett: Boston, 2007. } \author{Michael Rotondi, \email{mrotondi@yorku.ca}} \seealso{\code{\link{epi2x2}}} \examples{ \dontrun{Data for matched-cohort study, comparing smokers to non-smokers for the presence of lung cancer.} X <- cbind(c(15,5), c(19,61)); summary(mcNemar(X, alpha=0.05, force=TRUE)); } \keyword{multivariate} \keyword{design}epibasix/man/n4means.Rd0000755000176200001440000000460712463727332014510 0ustar liggesusers\name{n4means} \alias{n4means} \alias{print.n4means} \alias{summary.n4means} \title{Number of Subjects Required for a Randomized Trial with a Continuous Outcome} \description{ This function provides detailed sample size estimation information to determine the number of subjects that must be enrolled in a randomized trial with a continuous outcome.} \usage{n4means(delta, sigma, alpha=0.05, power=0.8, AR=1, two.tailed=TRUE, digits=3)} \arguments{ \item{delta}{The minimum detectable difference between population means.} \item{sigma}{The standard error of the outcome.} \item{AR}{The Allocation Ratio: One implies an equal number of subjects per treatment and control group (maximum efficiency), > 1, implies more subjects will be enrolled in the control group (e.g. in the case of costly intervention), < 1 implies more in the tretment group (rarely used).} \item{alpha}{The desired Type I Error Rate} \item{power}{The desired level of power, recall power = 1 - Type II Error.} \item{two.tailed}{Logical, If TRUE calculations are based on a two-tailed Type I error, if FALSE, a one-sided calculation is performed.} \item{digits}{Number of Digits to round calculations} } \details{ This function provides detailed information, similar to PROC POWER in SAS, but with less functionality and more concise output. It is used for sample size estimation in a randomized trial where the outcome is continuous, such as blood pressure, or weight. } \value{ \item{nE}{The minimum number of subjects required in the Experimental group.} \item{nC}{The minimum number of subjects required in the Control group.} \item{delta}{The minimum detectable difference between population means.} \item{sigma}{The standard error of the outcome.} \item{alpha}{The desired Type I Error Rate} \item{power}{The desired level of power, recall power = 1 - Type II Error.} \item{AR}{The Allocation Ratio} } \references{ Matthews JNS. Introduction to Randomized Controlled Clinical Trials (2nd Ed.) Chapman & Hall: New York, 2006. } \author{Michael Rotondi, \email{mrotondi@yorku.ca}} \seealso{\code{\link{n4props}}} \examples{ \dontrun{Suppose we wish to test whether a blood pressure medication reduces diastolic blood pressure by 10 mm Hg, at standard significance and power, assume the standard deviation is 10 mm Hg.} n4means(delta=10, sigma=10, alpha=0.05, power=0.80); } \keyword{design}epibasix/man/sensSpec.Rd0000755000176200001440000000610112463727362014720 0ustar liggesusers\name{sensSpec} \alias{sensSpec} \alias{print.sensSpec} \alias{summary.sensSpec} \title{Sensitivity and Specificity Analysis of a 2x2 Matrix} \description{ This function provides detailed information regarding the comparison of two competing methods, for example self-report and gold-standard treatment through a sensitivity/specificity analysis. } \usage{sensSpec(X, alpha=0.05, CL=TRUE, digits=3)} \arguments{ \item{X}{A 2x2 matrix, with Gold Standard Class A and B in the columns and Comparison Method A and B in the rows.} \item{CL}{Logical: If TRUE, Confidence Intervals are calculated and displayed in summary method.} \item{alpha}{The desired Type I Error Rate for Hypothesis Tests and Confidence Intervals} \item{digits}{Number of Digits to round calculations} } \details{ This function is designed to calculate Sensitivity, Specificity, Youden's J and Percent Agreement. These tools are used to assess the validity of a new instrument or self-report against the current gold standard. In general, self-report is less expensive, but may be subject to information bias. Computational formulae can be found in the reference. } \value{ \item{X}{The original input matrix.} \item{sens}{The point estimate of sensitivity} \item{spec}{The point estimate of specificity} \item{PA}{The point estimate of Percent Agreement} \item{YoudenJ}{The point estimate of Youden's J} \item{sens.s}{The standard deviation of sensitivity} \item{spec.s}{The standard deviation of specificity} \item{PA.s}{The standard deviation of Percent Agreement} \item{YoudenJ.s}{The standard deviation of Youden's J} \item{sens.CIL}{The lower bound of the constructed confidence interval for true sensitivity.} \item{sens.CIU}{The upper bound of the constructed confidence interval for true sensitivity} \item{spec.CIL}{The lower bound of the constructed confidence interval for true specificity.} \item{spec.CIU}{The upper bound of the constructed confidence interval for true specificity.} \item{PA.CIL}{The lower bound of the constructed confidence interval for Percent Agreement.} \item{PA.CIU}{The upper bound of the constructed confidence interval for Percent Agreement.} \item{YoudenJ.CIL}{The lower bound of the constructed confidence interval for Youden's J.} \item{YoudenJ.CIU}{The upper bound of the constructed confidence interval for Youden's J.} \item{alpha}{The desired Type I Error Rate for Hypothesis Tests and Confidence Intervals} \item{digits}{Number of Digits to round calculations} } \references{ Szklo M and Nieto FJ. Epidemiology: Beyond the Basics, Jones and Bartlett: Boston, 2007. } \note{ All confidence limits rely on simple asymptotic theory, as such, confidence limits may lie outside of [0,1]. A more accurate method is available in the twoby2 function of the Epi package, which employs a logit transformation. } \author{Michael Rotondi, \email{mrotondi@yorku.ca}} \seealso{\code{\link{kappa}}} \examples{ \dontrun{From Szklo and Nieto, p. 315} dat <- cbind(c(18,1), c(19,11)); summary(sensSpec(dat)); } \keyword{multivariate} \keyword{design}epibasix/man/epi2x2.Rd0000755000176200001440000000574312463727254014261 0ustar liggesusers\name{epi2x2} \alias{epi2x2} \alias{Contingency Table} \alias{print.epi2x2} \alias{summary.epi2x2} \title{Epidemiological 2x2 Contingency Table Analysis Tool} \description{ This function analyzes 2x2 tables assuming either a case-control or cohort study. Information such as Pearson's chi-squared test, the odds ratio, risk difference and relative risk are computed, as well as confidence intervals.} \usage{epi2x2(X,alpha=0.05, digits=3)} \arguments{ \item{X}{A 2x2 matrix in standard epidemiological format, that is, column one represents outcome present, column two outcome absent, while row one represents risk present and row two represents risk absent. This is crucial for correct computation of odds ratio and parameters.} \item{alpha}{The desired Type I Error Rate for Hypothesis Tests and Confidence Intervals} \item{digits}{Number of Digits to round calculations} } \details{ This function is similar to PROC FREQ in SAS, as it provides the comprehensive analysis of a 2x2 contingency table. Again, I must stress that the table must be entered in the appropriate format, or unsuitable estimates will result. In a case control study, cases should be entered as column one and controls as column two. } \value{ \item{X}{The original input matrix.} \item{Sy}{Value for Pearson's Chi-squared statistic (with continuity correction).} \item{Sy.p.value}{P-value for the hypothesis test of no association.} \item{Fisher.p.value}{P-value for the hypothesis test of no association. (Using Fisher's Exact Test)} \item{OR}{Point Estimate of the odds ratio.} \item{OR.CIL}{Lower Confidence Limit for the odds ratio.} \item{OR.CIU}{Upper Confidence Limit for the odds ratio.} \item{p1Co}{Row One Risk (Cohort Study)} \item{p2Co}{Row Two Risk (Cohort Study)} \item{rdCo}{Risk difference (Cohort Study). That is p1Co - p2Co.} \item{rdCo.CIL}{Lower Confidence Limit for Risk Difference in a cohort study.} \item{rdCo.CIU}{Upper Confidence Limit for Risk Difference in a cohort study.} \item{RR}{Relative Risk (Cohort Study)} \item{RR.CIL}{Lower Confidence Limit for Relative Risk in a cohort study.} \item{RR.CIU}{Upper Confidence Limit for Relative Risk in a cohort study.} \item{p1CC}{Column One Risk (Case-Control Study)} \item{p2CC}{Column Two Risk (Case-Control Study)} \item{rdCC}{Risk difference (Case-Control Study). That is p1CC - p2CC.} \item{rdCC.CIL}{Lower Confidence Limit for Risk Difference in a case-control study.} \item{rdCC.CIU}{Upper Confidence Limit for Risk Difference in a case-control study.} \item{alpha}{The desired Type I Error Rate for Hypothesis Tests and Confidence Intervals} \item{digits}{Number of Digits to round calculations} } \references{ Szklo M and Nieto FJ. Epidemiology: Beyond the Basics, Jones and Bartlett: Boston, 2007. } \author{Michael Rotondi, \email{mrotondi@yorku.ca}} \seealso{\code{\link{mcNemar}}} \examples{ data <- cbind(c(100, 225), c(58, 45)); summary(epi2x2(data)); } \keyword{multivariate} \keyword{design}epibasix/man/univar.Rd0000755000176200001440000000474612463727372014457 0ustar liggesusers\name{univar} \alias{univar} \alias{print.univar} \alias{summary.univar} \title{Univariate Analysis of a Single Variable} \description{ This function provides detailed univariate analysis for a single variable. Values include the sample mean, median, standard deviation and range, as well as tools for hypothesis tests and confidence intervals. } \usage{univar(X, alpha=0.05, mu0 = 0, shapiro=FALSE, digits=3)} \arguments{ \item{X}{A Vector of observed values from a continuous distribution} \item{alpha}{The desired Type I Error Rate for Hypothesis Tests and Confidence Intervals} \item{mu0}{The null hypothesis for the true population mean}. \item{shapiro}{Logical: TRUE returns the Shapiro-Wilks Test for normality, this portion calls the shapiro.test function.} \item{digits}{Number of Digits to round calculations} } \details{ This function provides a thorough summary of information within a vector. It conveniently calculates useful statistics at the call of a single command. Furthermore, it provides methods to test the hypothesis/construct confidence intervals for the true population mean.} \value{ \item{n}{Number of Observations Used} \item{mean}{The sample mean of the observations in X.} \item{median}{The sample median of the observations in X.} \item{min}{The sample minimum of the observations in X.} \item{max}{The sample maximum of the observations in X.} \item{s}{The sample standard deviation of the observations in X.} \item{var}{The sample variance of the observations in X.} \item{test}{The test statistic for the null hypothesis \eqn{\mu}{mu}} \item{p.value}{The p.value for the test statistic for \eqn{\mu}{mu}} \item{CIL}{The lower bound of the constructed confidence interval for \eqn{\mu}{mu}} \item{CIU}{The upper bound of the constructed confidence interval for \eqn{\mu}{mu}} \item{shapiro.statistic}{The value of the Shapiro-Wilks Statistic for Normality.} \item{shapiro.p.value}{The P-value of the Shapiro-Wilks Statistic for Normality.} \item{alpha}{The desired Type I Error Rate for Hypothesis Tests and Confidence Intervals} \item{mu0}{The null hypothesis for the true population mean}. \item{shapiro}{Logical: TRUE returns the Shapiro-Wilks Test for normality} \item{digits}{Number of Digits to round calculations} } \references{ Casella G and Berger RL. Statistical Inference (2nd Ed.) Duxbury: New York, 2002. } \author{Michael Rotondi, \email{mrotondi@yorku.ca}} \examples{ x <- rexp(100); univar(x); } \keyword{univar} epibasix/man/epiTTest.Rd0000755000176200001440000000505012463727304014674 0ustar liggesusers\name{epiTTest} \alias{epiTTest} \alias{print.epiTTest} \alias{summary.epiTTest} \title{Epidemiological T-Test Function} \description{ This function computes the standard two sample T-Test, as well as performing hypothesis tests and computing confidence intervals for the equality of both population means. } \usage{epiTTest(X,Y, alpha=0.05, pooled=FALSE, digits=3)} \arguments{ \item{X}{A vector of observed values of a continuous random variable.} \item{Y}{A vector of observed values of a continuous random variable.} \item{alpha}{The desired Type I Error Rate for Confidence Intervals} \item{pooled}{Logical: If TRUE, a pooled estimate of the variance is used. That is, the variance is assumed to be equal in both groups. If FALSE, the Satterthwaite estimate of the variance is used.} \item{digits}{Number of Digits to round calculations} } \details{ This function performs the simple two-sample T-Test, while providing detailed information regarding the analysis and summary information for both groups. Note that this function requires the input of two vectors, so if the data is stored in a matrix, it must be separated into two distinct vectors, X and Y. } \value{ \item{nx}{The number of observations in X.} \item{ny}{The number of observations in Y.} \item{mean.x}{The sample mean of X.} \item{mean.y}{The sample mean of Y.} \item{s.x}{The standard deviation of X.} \item{s.y}{The standard deviation of Y.} \item{d}{The difference between sample means, that is, mean.x - mean.y.} \item{s2p}{The pooled variance, when applicable.} \item{df}{The degrees of freedom for the test.} \item{TStat}{The test statistic for the null hypothesis \eqn{\mu_X - \mu_Y = 0}{mu_X - mu_Y = 0}.} \item{p.value}{The P-value for the test statistic for \eqn{\mu_X - \mu_Y = 0}{mu_X - mu_Y = 0}.} \item{CIL}{The lower bound of the constructed confidence interval for \eqn{\mu_X - \mu_Y = 0}{mu_X - mu_Y = 0}.} \item{CIU}{The lower bound of the constructed confidence interval for \eqn{\mu_X - \mu_Y = 0}{mu_X - mu_Y = 0}.} \item{pooled}{Logical: as above for assuming variances are equal.} \item{alpha}{The desired Type I Error Rate for Confidence Intervals} } \references{ Casella G and Berger RL. Statistical Inference (2nd Ed.) Duxbury: New York, 2002. Szklo M and Nieto FJ. Epidemiology: Beyond the Basics, Jones and Bartlett: Boston, 2007. } \author{Michael Rotondi, \email{mrotondi@yorku.ca}} \examples{ X <- rnorm(100,10,1); Y <- rnorm(100); summary(epiTTest(X,Y, pooled = FALSE)); } \keyword{multivariate} \keyword{htest} epibasix/man/diffDetect.Rd0000755000176200001440000000430712463727242015201 0ustar liggesusers\name{diffDetect} \alias{diffDetect} \alias{Mean Difference} \alias{summary.diffDetect} \alias{print.diffDetect} \title{Mean Difference Detetion Tool} \description{Provides Minimum Detectable Difference in Means Between Two Populations for fixed values of sigma and n. Useful for experimental design for randomized trials. } \usage{diffDetect(N,sigma,alpha=0.05, power=0.8, two.tailed=TRUE)} \arguments{ \item{N}{A Vector (or single value) of fixed sample sizes.} \item{sigma}{A Vector (or single value) of fixed standard deviations sizes.} \item{alpha}{The desired Type I Error Rate} \item{power}{The desired level of power, recall power = 1 - Type II Error.} \item{two.tailed}{Logical, If TRUE calculations are based on a two-tailed Type I error, if FALSE, a one-sided calculation is performed.} } \details{ This function can be used as a tool for sensitivity analysis on the choice of population standard deviation. As is often the case, the sample size is fixed by practical considerations, such as cost or difficulty recruiting subjects. This simple tool may help determine whether it is worth performing an experiment that can only detect a given calculated difference between means. } \value{ \item{delta}{A Matrix of minimum detectable differences for fixed values of n and sigma} \item{N}{A Vector (or single value) of specified sample sizes.} \item{sigma}{A Vector (or single value) of specified standard deviations sizes.} \item{alpha}{The desired Type I Error Rate} \item{power}{The desired level of power, recall power = 1 - Type II Error.} \item{two.tailed}{Logical, If TRUE calculations are based on a two-tailed Type I error, if FALSE, a one-sided calculation is performed.} } \references{ Matthews JNS. Introduction to Randomized Controlled Clinical Trials (2nd Ed.) Chapman & Hall: New York, 2006. } \author{Michael Rotondi, \email{mrotondi@yorku.ca}} \examples{ \dontrun{Suppose, for financial considerations we can only enroll 100 people in a blood pressure medication trial. What is the minimum difference we can detect between means if sigma = 1, 5 or 10 mmHg, at standard levels?} n <- 100; sigma <- c(1, 5, 10); diffDetect(n,sigma); } \keyword{design}