← Knowledge

Public EcoRouter Knowledge · AI-generated content ·

how to create a business model in r when you just have historical order data and you want to predict how a price change

The question

how to create a business model in r when you just have historical order data and you want to predict how a price change would change number of orders?

Efficient

To model the relationship between price changes and order volume using historical data in R, you generally follow a sequence of data preparation, model selection, and simulation. Since you are trying to understand how a change in XX (Price) affects YY (Orders), you are essentially building a Demand Elasticity Model.

Here is a straightforward approach:

1. Data Preparation

Your data should be aggregated to a level that captures the price variation (e.g., daily or weekly). Ensure your dataframe includes at least:

  • date: To account for seasonality or trends.
  • orders: The count of orders.
  • price: The average or median price during that period.
  • Optional: Controls like marketing_spend, holiday_flag, or competitor_price.

2. Choose Your Model

Since orders are counts (non-negative integers), a standard Linear Regression often leads to biased results. Use one of these instead:

  • Log-Log Regression (Elasticity Model): If you take the natural log of both price and orders, the coefficient of price represents the price elasticity of demand (a 1% change in price leads to an XX% change in orders).
    • R command: lm(log(orders) ~ log(price), data = your_data)
  • Poisson or Negative Binomial Regression: Better for count data. If your variance is much higher than your mean (common in order data), use glm.nb from the MASS package.
    • R command: MASS::glm.nb(orders ~ price, data = your_data)

3. Implementation Steps in R

R
# Load libraries
library(tidyverse)
library(MASS)

# 1. Visualize the relationship first
ggplot(your_data, aes(x = price, y = orders)) + 
  geom_point() + 
  geom_smooth(method = "glm", method.args = list(family = "poisson"))

# 2. Fit the model (Example using Poisson to handle count data)
model <- glm(orders ~ price + marketing_spend + month, 
             data = your_data, 
             family = "poisson")

# 3. Check for significance
summary(model)

4. Predicting the Effect of a Price Change

Once the model is trained, you can perform a "what-if" analysis by creating a new dataframe with a hypothetical price:

R
# Create a scenario where you increase price by 10%
new_scenario <- your_data %>%
  summarise(price = mean(price) * 1.1,
            marketing_spend = mean(marketing_spend),
            month = "January")

# Predict expected orders
predicted_orders <- predict(model, newdata = new_scenario, type = "response")

Important Considerations

  • Correlation vs. Causality: Historical data shows what happened, not necessarily why. If you only ever lowered prices during slow months, the model might incorrectly think low prices cause slow months. If possible, include "control" variables like seasonality or holidays to prevent this bias.
  • External Factors: If you have data on competitor pricing or economic indicators, include them. Price elasticity is rarely static and often depends on what else is happening in the market.
  • The "Zero" Problem: If you have many days with zero orders, ensure your model handles zero-inflation (e.g., pscl::zeroinfl), though for most businesses, Poisson/NB is sufficient.

Start with the Log-Log model first. It is the industry standard for pricing discussions because it gives you a clear percentage-based interpretation that is easy to explain to stakeholders.

Answering this used an estimated 90% less than EcoRouter’s configured frontier baseline

Routed to
Efficient
Tokens
489 in / 828 out
Cost
$0.0014
Baseline
$0.01

Figures recorded by EcoRouter when this answer was generated, and fixed at that moment. Cost comparisons are against a configured reference model, not a measurement of electricity, carbon or water.

Ask about this

Ask EcoRouter a follow-up using this Knowledge as context. Nothing becomes public unless you choose to publish it.

Ask a follow-up
0 views

Comments

No comments yet.