data(MktDATA, package = "UBStats")
# Proportions of success defined on non-binary and
# non-logical vectors; 'success' coded same way
# for both vectors
# - Using x,y: build vectors with data on the two groups
WouldSuggest_F <- MktDATA$WouldSuggest[MktDATA$Gender == "F"]
WouldSuggest_M <- MktDATA$WouldSuggest[MktDATA$Gender == "M"]
TEST.diffprop(x = WouldSuggest_M, y = WouldSuggest_F,
success.x = "Yes", pdiff0 = 0.1, alternative = "less")
PastCampaigns_F<-MktDATA$PastCampaigns[MktDATA$Gender=="F"]
PastCampaigns_M<-MktDATA$PastCampaigns[MktDATA$Gender=="M"]
TEST.diffprop(x = PastCampaigns_M, y = PastCampaigns_F,
success.x = 0, pdiff0 = 0.2)
# - Using x,by: groups identified by ordered levels of by
TEST.diffprop(x = PastCampaigns, by = Gender,
success.x=0, pdiff0 = 0.2, data = MktDATA)
# Since order is F, M, test is on prop(F) - prop(M)
# To get the interval for prop(M) - prop(F)
Gender.R <- factor(MktDATA$Gender, levels = c("M", "F"))
TEST.diffprop(x = PastCampaigns, by = Gender.R,
success.x=0, pdiff0 = 0.2, data = MktDATA)
# Proportions of success defined based on
# binary or logical vectors; 'success'
# coded same way for both vectors
# - Binary variable (success=1): based on x,y
LastCampaign_F<-MktDATA$LastCampaign[MktDATA$Gender=="F"]
LastCampaign_M<-MktDATA$LastCampaign[MktDATA$Gender=="M"]
TEST.diffprop(x = LastCampaign_M, y = LastCampaign_F)
# - Binary variable (success=1): based on x,y
# see above for recoding of levels of Gender
TEST.diffprop(x = LastCampaign, by = Gender, data = MktDATA)
Gender.R <- factor(MktDATA$Gender, levels = c("M", "F"))
TEST.diffprop(x = LastCampaign, by = Gender.R, data = MktDATA)
# - Logical variable (success=TRUE): based on x,y
Deals_w_child <- MktDATA$Deals.ge50[MktDATA$Children>0]
Deals_no_child <- MktDATA$Deals.ge50[MktDATA$Children==0]
TEST.diffprop(x = Deals_w_child, y = Deals_no_child,
pdiff0 = 0.2, alternative = "less",)
# Proportions defined on
# non-binary and non-logical vectors, with 'success'
# coded differently (only specification x,y is reasonable here)
WouldSuggest_Other<-c(rep("OK",310),rep("KO",650-310))
TEST.diffprop(x = WouldSuggest, y = WouldSuggest_Other,
success.x = "Yes", success.y = "OK",
pdiff0 = 0.1, alternative = "greater",
data = MktDATA)
# Proportions based on combined conditions
# - Build logical vector/s indicating whether a condition
# is satisfied
IsTop<-MktDATA$AOV>80
IsTop_OK<-IsTop[MktDATA$WouldSuggest == "Yes"]
IsTop_KO<-IsTop[MktDATA$WouldSuggest == "No"]
TEST.diffprop(x = IsTop_OK, y = IsTop_KO, pdiff0 = 0.05,
alternative = "greater")
Deals<-MktDATA$NDeals>=5
Deals_Married <- Deals[MktDATA$Marital_Status=="Married" &
MktDATA$Children==0]
Deals_Single <- Deals[MktDATA$Marital_Status=="Single"]
TEST.diffprop(x = Deals_Married, y = Deals_Single,
alternative = "less")
# Output results
out.test_diffP<-TEST.diffprop(x = Deals_Married, y = Deals_Single,
alternative = "less")
# Arguments force.digits and use.scientific
# An input variable taking very low values
HighAOV <- MktDATA$AOV>150
# - Default: manages possible excess of rounding
TEST.diffprop(x = HighAOV[MktDATA$Gender=="M"],
y = HighAOV[MktDATA$Gender=="F"])
# - Force to the exact number of digits (default, 2)
TEST.diffprop(x = HighAOV[MktDATA$Gender=="M"],
y = HighAOV[MktDATA$Gender=="F"],
force.digits = TRUE)
# - Allow scientific notation
TEST.diffprop(x = HighAOV[MktDATA$Gender=="M"],
y = HighAOV[MktDATA$Gender=="F"],
use.scientific = TRUE)
Run the code above in your browser using DataLab