data(MktDATA, package = "UBStats")
# Independent samples (default type), UNKNOWN variances
# Bilateral test on difference between means of males and females
# - Using x,y: build vectors with data on the two groups
AOV_M <- MktDATA$AOV[MktDATA$Gender == "M"]
AOV_F <- MktDATA$AOV[MktDATA$Gender == "F"]
TEST.diffmean(x = AOV_M, y = AOV_F, mdiff0 = 0)
# - Using x,by: groups identified by ordered levels of by
TEST.diffmean(x = AOV, by = Gender, mdiff0 = 0, data = MktDATA)
# Since order is F, M, hypothesis are on mean(F) - mean(M)
# To test hypotheses on mean(M) - mean(F)
Gender.R <- factor(MktDATA$Gender, levels = c("M", "F"))
TEST.diffmean(x = AOV, by = Gender.R , mdiff0 = 0,
data = MktDATA)
# - Testing also hypotheses on equality of unknown variances
TEST.diffmean(x = AOV_M, y = AOV_F, mdiff0 = 0,
var.test = TRUE)
# - Output results: test on differences
out.test_diffM<-TEST.diffmean(x = AOV_M, y = AOV_F)
# - Output results: list with both test on means and variances
out.test_diffM.V<-TEST.diffmean(x = AOV_M, y = AOV_F, var.test = TRUE)
# Independent samples (default type), KNOWN variances
# Test hypotheses on the difference between means of males and females
# - Using x,y: build vectors with data on the two groups
AOV_M <- MktDATA$AOV[MktDATA$Gender == "M"]
AOV_F <- MktDATA$AOV[MktDATA$Gender == "F"]
TEST.diffmean(x = AOV_M, y = AOV_F, mdiff0 = 10,
alternative = "greater", sigma.x = 10, sigma.y = 20)
# - Using x,by: groups identified by ordered levels of by
# Adjust considering the ordering of levels
TEST.diffmean(x = AOV, by = Gender, mdiff0 = -10,
alternative = "less",
sigma.by = c("M" = 10, "F"=20), data = MktDATA)
# To change the sign, order levels as desired
Gender.R <- factor(MktDATA$Gender, levels = c("M", "F"))
TEST.diffmean(x = AOV, by = Gender.R, mdiff0 = 10,
alternative = "greater",
sigma.by = c("M" = 10, "F"=20), data = MktDATA)
# - Output results
out.test_diffM<-TEST.diffmean(x = AOV_M, y = AOV_F, mdiff0 = 10,
alternative = "greater",
sigma.x = 10, sigma.y = 20)
# Paired samples: UNKNOWN variances
# - Default settings
TEST.diffmean(x = NStore_Purch, y = NWeb_Purch,
type = "paired",
mdiff0 = 1.5, alternative = "greater", data=MktDATA)
# Paired: KNOWN variances
TEST.diffmean(x = NStore_Purch, y = NWeb_Purch,
type = "paired", mdiff0 = 1.5, alternative = "greater",
sigma.d = 2, data = MktDATA)
# - Output results
out.test_diffM<-TEST.diffmean(x = NStore_Purch,
y = NWeb_Purch,
type = "paired", mdiff0 = 1.5, alternative = "greater",
sigma.d = 2, data = MktDATA)
# Arguments force.digits and use.scientific
# An input variable taking very low values
SmallX<-MktDATA$AOV/50000
SmallX_M <- SmallX[MktDATA$Gender == "M"]
SmallX_F <- SmallX[MktDATA$Gender == "F"]
# - Default output
TEST.diffmean(x = SmallX_M, y = SmallX_F)
# - Request to use the exact number of digits (default, 2)
TEST.diffmean(x = SmallX_M, y = SmallX_F,
force.digits = TRUE)
# - Request to allow scientific notation
TEST.diffmean(x = SmallX_M, y = SmallX_F,
use.scientific = TRUE)
Run the code above in your browser using DataLab