DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Coding
  3. Languages
  4. R: Modelling a Conversion Rate with a Binomial Distribution

R: Modelling a Conversion Rate with a Binomial Distribution

Mark Needham user avatar by
Mark Needham
·
Feb. 08, 13 · Interview
Like (0)
Save
Tweet
Share
2.91K Views

Join the DZone community and get the full member experience.

Join For Free

As part of some work Sid and I were doing last week we wanted to simulate the conversion rate for an A/B testing we were planning.

We started with the following function which returns the simulated conversion rate for a given conversion rate of 12%:

generateConversionRates <- function(sampleSize) {
	sample_a <- rbinom(seq(0, sampleSize), 1, 0.12)
	conversion_a <- length(sample_a[sample_a == 1]) / sampleSize
 
	sample_b <- rbinom(seq(0, sampleSize), 1, 0.12)
	conversion_b <- length(sample_b[sample_b == 1]) / sampleSize
 
	c(conversion_a, conversion_b)
}

If we call it:

> generateConversionRates(10000)
[1] 0.1230 0.1207

We have a 12.3% conversion rate on A and a 12.07% conversion rate on B based on 10,000 sample values.

We then wrote the following function to come up with 1000 versions of those conversion rates:

generateSample <- function(sampleSize) {
	lapply(seq(1, 1000), function(x) generateConversionRates(sampleSize))
}

We can call that like this:

> getSample(10000)
[[998]]
[1] 0.1179 0.1216
 
[[999]]
[1] 0.1246 0.1211
 
[[1000]]
[1] 0.1248 0.1234

We were then using these conversion rates to try and work out how many samples we needed to include in an A/B test to have reasonable confidence that it represented the population.

We actually ended up abandoning that exercise but I thought I’d record the code because I thought it was pretty interesting.

R (programming language) Distribution (differential geometry)

Published at DZone with permission of Mark Needham, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • How To Create and Edit Excel XLSX Documents in Java
  • Top 5 Java REST API Frameworks
  • Fraud Detection With Apache Kafka, KSQL, and Apache Flink
  • Select ChatGPT From SQL? You Bet!

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: