R
Completed
-
Section 1: Getting Started
-
Section 2: Core Syntax
-
Section 3: Data Structures
-
Section 4: Data Manipulation
-
Section 5: Visualization and Statistics
-
Section 6: Advanced R
-
Section 7: Practical Projects
-
Section 8: Interview Practice
-
Section 9: More Practice Exercises
-
Section 10: Shiny Apps in Depth
-
Section 11: More Data Wrangling
-
Section 12: Tidyverse Deep Dive
-
Section 13: Statistical Modeling Deep Dive
-
Section 14: Machine Learning in R
-
Section 15: R Visualization Deep Dive
-
Section 16: R Package Development Deep Dive
-
Section 17: R for Reproducible Research
-
Section 18: R and Databases
-
Section 19: R Performance Optimization
-
Section 20: Bioinformatics and Specialized R
-
Section 21: More Shiny Practice
-
Section 22: More Practice Exercises
-
Section 23: R Data Structures Deep Dive
-
Section 24: More Interview and Review
-
Section 25: R for Business Analytics
-
Section 26: R Text Mining and NLP
-
Section 27: R Spatial Data Analysis
-
Section 28: R Deep Learning
-
Section 29: Advanced Statistical Techniques
-
Section 30: R Object Systems Deep Dive
-
Section 31: R Environments and Metaprogramming
-
Section 32: R for Finance
-
Section 33: R for Clinical and Health Data
-
Section 34: More Shiny Advanced Practice
-
Section 35: R Data Cleaning Deep Dive
-
Section 36: R Reporting Automation
-
Section 37: More Practical Projects Round 2
-
Section 38: R Ecosystem and Career
-
Section 39: More Visualization Practice
-
Section 40: R for Experimentation
-
Section 41: R for Genomics and Bioinformatics Deep Dive
-
Section 42: R for Marketing Analytics
-
Section 43: R Data Import/Export Deep Dive
-
Section 44: R String Processing Deep Dive
-
Section 45: R for Actuarial and Insurance Analytics
-
Section 46: R Testing and Quality Assurance Deep Dive
-
Section 47: R Version Control and Collaboration
-
Section 48: R Advanced Functional Programming
-
Section 49: R for Supply Chain and Operations
-
Section 50: More Practice Exercises Round 3
-
Section 51: R Dashboards and BI Integration
-
Section 52: R Data Governance and Ethics
-
Section 53: More Modeling Practice
-
Section 54: R Final Capstone Projects
-
Section 55: R for Sports Analytics
-
Section 56: More Interview Practice Round 2
-
Section 57: R Networking and APIs
-
Section 58: R for Environmental Science
-
Section 59: R Notebook and Documentation Practices
-
Section 60: More Data Wrangling Mastery
-
Section 61: R for A/B Testing at Scale
-
Section 62: R Package Ecosystem Deep Dive
168: Campaign Response Analysis
How do I actually calculate the response rate across different customer segments?
When I'm looking at a campaign, I don't care about the overall average as much as I care about the variance. If your overall response rate is 2%, but one specific segment is at 15%, that's where the real story is. In R, the cleanest way to do this is using dplyr to group your data and then taking the mean of your binary response column (assuming 1 is "responded" and 0 is "didn't").
Let's say we're analyzing a "Summer Garden Sale" email blast. We have a dataset called campaign_data with columns for segment (e.g., 'Homeowner', 'Renter', 'Commercial') and responded.
library(dplyr)
response_summary <- campaign_data %>%
group_by(segment) %>%
summarise(
total_sent = n(),
response_rate = mean(responded),
count_responded = sum(responded)
) %>%
arrange(desc(response_rate))
print(response_summary)
I always include the total_sent count. Why? Because a 100% response rate is meaningless if you only sent the email to two people. Always keep the sample size in sight.
How can I tell if a difference in response rates is actually significant or just random noise?
You'll see this happen all the time: the 'Homeowner' segment has a 4.2% response rate and the 'Renter' segment has 3.8%. It looks better, but is it statistically better? You can't just eyeball this. Since we're dealing with proportions, I usually reach for prop.test().
Here is how I'd compare two specific groups from our garden campaign:
# Let's pull the numbers for Homeowners vs Renters
homeowner_resps <- sum(campaign_data$responded[campaign_data$segment == "Homeowner"])
homeowner_total <- sum(campaign_data$segment == "Homeowner")
renter_resps <- sum(campaign_data$responded[campaign_data$segment == "Renter"])
renter_total <- sum(campaign_data$segment == "Renter")
# Run the proportion test
test_result <- prop.test(x = c(homeowner_resps, renter_resps),
n = c(homeowner_total, renter_total))
print(test_result$p.value)
If that p-value is below 0.05, you can feel reasonably confident that the difference is real. If it's higher, I'd tell my stakeholders that the segment difference is likely just noise and not a reliable lever for future campaigns.
What's the best way to model which factors actually drove the response?
Once you've found that a segment differs, you usually want to know why. Maybe it's not just the segment, but a combination of age, previous spend, and the time of day the email was sent. For binary outcomes (Yes/No), linear regression is out; you need Logistic Regression using glm().
I like to use the binomial family here. It gives us the log-odds of a response, which we can then interpret.
# Modeling response based on age, total_spend, and segment
response_model <- glm(responded ~ age + total_spend + segment,
data = campaign_data,
family = "binomial")
summary(response_model)
When you look at the summary, don't get bogged down in the raw coefficients—they're hard to read. Instead, I usually wrap the coefficients in exp() to get the Odds Ratios. An odds ratio of 1.2 for total_spend means that for every unit increase in spend, the odds of responding increase by 20%. That's a number a marketing manager actually understands.
📋 Practical Task
Analyzing the Winter Clearance Campaign Efficiency
You have been handed a dataset winter_campaign_df containing 5,000 rows. The columns are customer_id, age_group ('18-30', '31-50', '51+'), discount_level ('10%', '20%', '30%'), and converted (1 if they bought something, 0 if not).
Your task is to write a script that:
- Calculates the conversion rate for each
discount_level, sorted from highest to lowest. - Performs a
prop.testto determine if the difference in conversion rates between the '10%' and '30%' discount groups is statistically significant (p < 0.05). - Builds a logistic regression model to see if
age_groupanddiscount_levelare significant predictors ofconverted. - Prints the Odds Ratios for the model coefficients.
There are no comments for now.