survey_raw <- read.csv(
  "Customer Shopping and Promotion Preferences raw data.csv",
  stringsAsFactors = FALSE,
  check.names = FALSE
)

dim(survey_raw)
## [1] 53 31
survey_clean <- survey_raw[-c(1, 2), ]

dim(survey_clean)
## [1] 51 31
table(survey_clean$Finished, useNA = "ifany")
## 
##  1 
## 51
table(survey_clean$Status, useNA = "ifany")
## 
##  0 
## 51
table(survey_clean$Progress, useNA = "ifany")
## 
## 100 
##  51
# Select survey question columns
question_cols <- grep("^Q[0-9]", names(survey_clean), value = TRUE)

# Count missing or blank answers in each question
sapply(survey_clean[question_cols], function(x) {
  sum(is.na(x) | trimws(x) == "")
})
##   Q2   Q3   Q4   Q5   Q6   Q7 Q8_1 Q8_2 Q8_3 Q8_4 Q8_5   Q9 
##    2    2    3    2    2    2    3    3    4    4    4    3
# Identify missing answers
missing_answers <- sapply(survey_clean[question_cols], function(x) {
  is.na(x) | trimws(x) == ""
})

# Identify responses with no survey answers
empty_responses <- rowSums(missing_answers) == length(question_cols)
sum(empty_responses)
## [1] 2
# Remove those responses
survey_clean <- survey_clean[!empty_responses, ]

# Check remaining responses and missing answers
dim(survey_clean)
## [1] 49 31
sapply(survey_clean[question_cols], function(x) {
  sum(is.na(x) | trimws(x) == "")
})
##   Q2   Q3   Q4   Q5   Q6   Q7 Q8_1 Q8_2 Q8_3 Q8_4 Q8_5   Q9 
##    0    0    1    0    0    0    1    1    2    2    2    1
# Convert question answers to numeric codes
survey_clean[question_cols] <- lapply(
  survey_clean[question_cols],
  function(x) as.numeric(trimws(x))
)

# Check the conversion
str(survey_clean[question_cols])
## 'data.frame':    49 obs. of  12 variables:
##  $ Q2  : num  1 2 2 3 2 2 2 3 3 3 ...
##  $ Q3  : num  1 1 3 3 6 3 6 6 3 1 ...
##  $ Q4  : num  1 3 3 3 4 3 5 5 3 3 ...
##  $ Q5  : num  1 2 1 1 1 1 1 2 2 3 ...
##  $ Q6  : num  2 4 3 2 4 3 5 3 3 2 ...
##  $ Q7  : num  4 5 3 2 3 2 5 4 2 2 ...
##  $ Q8_1: num  NA 0 3 4 6 0 2 7 5 7 ...
##  $ Q8_2: num  NA 0 2 2 3 7 5 4 2 9 ...
##  $ Q8_3: num  NA 6 6 1 7 5 2 3 8 8 ...
##  $ Q8_4: num  NA 2 5 5 8 1 2 6 8 10 ...
##  $ Q8_5: num  NA 2 7 0 3 3 1 5 5 10 ...
##  $ Q9  : num  2 1 2 1 1 1 1 2 2 2 ...
analysis_data <- data.frame(
  discount_willingness = survey_clean$Q6,
  personalization_comfort = survey_clean$Q7,
  discount_importance = 10 - survey_clean$Q8_1
)

# Count responses missing a variable needed for these models
sum(!complete.cases(analysis_data))
## [1] 1
# Keep the same complete responses for both regressions
analysis_data <- analysis_data[complete.cases(analysis_data), ]

dim(analysis_data)
## [1] 48  3
simple_model <- lm(
  discount_willingness ~ personalization_comfort,
  data = analysis_data
)

summary(simple_model)
## 
## Call:
## lm(formula = discount_willingness ~ personalization_comfort, 
##     data = analysis_data)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -2.16733 -0.69310 -0.03727  0.83267  2.33941 
## 
## Coefficients:
##                         Estimate Std. Error t value Pr(>|t|)    
## (Intercept)               2.2839     0.3765   6.066  2.3e-07 ***
## personalization_comfort   0.3767     0.1134   3.321  0.00176 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.007 on 46 degrees of freedom
## Multiple R-squared:  0.1934, Adjusted R-squared:  0.1759 
## F-statistic: 11.03 on 1 and 46 DF,  p-value: 0.001761
multiple_model <- lm(
  discount_willingness ~ personalization_comfort + discount_importance,
  data = analysis_data
)

summary(multiple_model)
## 
## Call:
## lm(formula = discount_willingness ~ personalization_comfort + 
##     discount_importance, data = analysis_data)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -2.09198 -0.63518 -0.07235  0.78539  2.39231 
## 
## Coefficients:
##                         Estimate Std. Error t value Pr(>|t|)    
## (Intercept)              2.22048    0.43341   5.123  6.1e-06 ***
## personalization_comfort  0.37430    0.11481   3.260  0.00213 ** 
## discount_importance      0.01291    0.04232   0.305  0.76177    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.017 on 45 degrees of freedom
## Multiple R-squared:  0.1951, Adjusted R-squared:  0.1593 
## F-statistic: 5.454 on 2 and 45 DF,  p-value: 0.007572
set.seed(123)

plot(
  jitter(analysis_data$personalization_comfort, amount = 0.08),
  jitter(analysis_data$discount_willingness, amount = 0.08),
  xlab = "Personalization comfort (Q7 score)",
  ylab = "Discount willingness (Q6 score)",
  main = "Personalization Comfort and Discount Willingness",
  pch = 19,
  col = adjustcolor("steelblue", alpha.f = 0.6)
)

abline(simple_model, col = "red", lwd = 2)

write.csv(
  analysis_data,
  "survey_clean.csv",
  row.names = FALSE
)

file.exists("survey_clean.csv")
## [1] TRUE

#Cleaning Explanation I deleted two Qualtrics metadata rows and imported 51 survey responses. Two responses had no survey answers, so I deleted them even though all of the responses were marked as complete. I chose three variables for regression—discount willingness, personalization comfort, and discount importance—after converting question answers to numerical codes. Higher values indicate greater relevance because I reversed the discount important using 10 minus the initial score. One more response was eliminated from both regressions since it did not include the answer required by the models. There are three variables, 48 replies, and no respondent identities in the final analytic dataset.

#Resluts Explanation Personalisation comfort was by far the most important of the predictors. Of the 48 responses, the simple regression coefficient for comfort was 0.3767 (a one point increase in comfort was associated with a 0.38 point increase in willingness to discount). This was pretty much unchanged at 0.3743 when discount importance was controlled for. R-squared went up only from 19.34% to 19.51% and discount importance wasn’t significant. The models were very similar as discount importance didn’t add much to the explanation. Adjusted R-squared actually went down which is as it should do when you’re accounting for additional predictors (Penn State, n.d.). The scatterplot showed a clear upward trend, though the responses were all over the place around the line. This is of course just an indication of association rather than causation. If I were to repeat this study I would recruit a larger and more diverse sample, improve the wording of the questions and look at the missing responses. I’d also check the regression assumptions and given that the outcome is a set of 5 ordered response categories I’d consider ordinal regression rather than the simple linear regression we’ve used here.

Penn State. (n.d.). Multiple linear regression. STAT 501: Regression Methods. https://online.stat.psu.edu/stat501/Lesson05