# assuming a skewed sample with only 1/3 women and 2/3 men
input_data <- data.frame(tch = round(rnorm(n = 250, mean = 8, sd = 1.5), digits = 2),
ch = round(rnorm(n = 250, mean = 12, sd = 2), digits = 2),
ex = round(rnorm(n = 250, mean = 13, sd = 1), digits = 2),
tex = round(rnorm(n = 250, mean = 15, sd = 1), digits = 2),
gender = sample(x = c("male", "female"),
size = 250,
replace = TRUE,
prob = c(2/3, 1/3)))
# ... and in which women have on average 1.5x the price acceptance of men
input_data$tch[input_data$gender == "female"] <- input_data$tch[input_data$gender == "female"] * 1.5
input_data$ch[input_data$gender == "female"] <- input_data$ch[input_data$gender == "female"] * 1.5
input_data$ex[input_data$gender == "female"] <- input_data$ex[input_data$gender == "female"] * 1.5
input_data$tex[input_data$gender == "female"] <- input_data$tex[input_data$gender == "female"] * 1.5
# creating a sample design object using the survey package
# ... assuming that gender is balanced equally in the population of 10000
input_data$gender_pop <- 5000
input_design <- survey::svydesign(ids = ~ 1, # no clusters
probs = NULL, # hence no cluster samling probabilities,
strata = input_data$gender, # stratified by gender
fpc = input_data$gender_pop, # strata size in the population
data = input_data)
# data object used as input: no need to specify single variables
output_weighted_psm <- psm_analysis_weighted(toocheap = "tch",
cheap = "ch",
expensive = "ex",
tooexpensive = "tex",
design = input_design)
summary(output_weighted_psm)
Run the code above in your browser using DataLab