diffmean.CI: Confidence Interval for the Difference between the Means of...

Description Usage Arguments Details Value Examples

View source: R/diffmean.CI.R

Description

diffmean.CI provides a pointwise estimation and a confidence interval for the difference between the means of two Normal populations in different scenarios: population variances known or unknown, population variances assumed equal or not, and paired or independent populations.

Usage

1
2
3
diffmean.CI(x1, x2, sigma1 = NULL, sigma2 = NULL, sc1 = NULL,
  sc2 = NULL, s1 = NULL, s2 = NULL, n1 = NULL, n2 = NULL,
  paired = FALSE, var.equal = FALSE, conf.level)

Arguments

x1

numeric vector or value corresponding with either one of the samples or the sample mean.

x2

numeric vector or value corresponding with either one of the samples or the sample mean.

sigma1

if known, a single numeric value corresponding with one of the population standard deviation.

sigma2

if known, a single numeric value corresponding with the other population standard deviation.

sc1

a single numeric value corresponding with the cuasi-standard deviation of one sample.

sc2

a single numeric value corresponding with the cuasi-standard deviation of the other sample.

s1

a single numeric value corresponding with the standard deviation of one sample.

s2

a single numeric value corresponding with the standard deviation of the other sample.

n1

a single positive integer value corresponding with the size of one sample; not needed if the sample is provided.

n2

a single positive integer value corresponding with the size of the other sample; not needed if the sample is provided.

paired

logical value indicating whether the populations are paired or independent; default to FALSE.

var.equal

logical value indicating whether to treat the two variances as being equal. If TRUE then the pooled variance is used to estimate the variance, otherwise the Dixon and Massey approximation to the degrees of freedom is used; default to FALSE.

conf.level

a single numeric value corresponding with the confidence level of the interval; must be a value in (0,1).

Details

If sigma1 and sigma2 are given, known population variances formula is applied; the unknown one is used in other case.

If paired is TRUE then both x1 and x2 must be specified and their sample sizes must be the same. If paired is null, then it is assumed to be FALSE.

For var.equal=TRUE, the formula of the pooled variance is \frac{(n1-1)sc1^2+(n2-1)sc2^2}{n1+n2-2}.

Value

A list containing the following components:

estimate

numeric value corresponding with the difference between the sample means.

CI

a numeric vector of length two containing the lower and upper bounds of the confidence interval.

Independently on the user saving those values, the function provides a summary of the result on the console.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
#Given unpaired samples with known population variance
dat1=rnorm(20,mean=2,sd=1);dat2=rnorm(30,mean=2,sd=1.5)
diffmean.CI(dat1,dat2,sigma1=1,sigma2=1.5,conf.level=0.9)

#Given unpaired samples with unknown but equal population variances
dat1=rnorm(20,mean=2,sd=1);dat2=rnorm(30,mean=2,sd=1)
diffmean.CI(dat1,dat2,paired=FALSE,var.equal=TRUE,conf.level=0.9)

#Given the characteristics of unpaired samples with unknown and different population variances
dat1=rnorm(20,mean=2,sd=1);dat2=rnorm(30,mean=2,sd=1)
x1=mean(dat1);x2=mean(dat2);sc1=sd(dat1);sc2=sd(dat2);n1=length(dat1);n2=length(dat2)
diffmean.CI(x1,x2,sc1=sc1,sc2=sc2,n1=n1,n2=n2,paired=FALSE,var.equal=FALSE,conf.level=0.9)

#Given paired samples
dat1=rnorm(20,mean=2,sd=1);dat2=dat1+rnorm(20,mean=0,sd=0.5)
diffmean.CI(dat1,dat2,paired=TRUE,conf.level=0.9)

LearningStats documentation built on April 21, 2021, 9:06 a.m.