4
$\begingroup$

Suppose I have some simple data for when someone buys or not buys something at a certain price, looking something like this:

ind    buy price
1      1   11
2      1   14
3      0   20
4      1   13
5      1   19
6      0   16
.      .   .
.      .   .
.      .   .
10000  1   14

Where 1 would mean buying and 0 not buying at that certain price, the numbers are just made up. I would like to fit a logistic regression to this data, dont really care in what software/language but this example is in python with the result:

                        Logit Regression Results                           
==============================================================================
Dep. Variable:              dependent   No. Observations:                  306
Model:                          Logit   Df Residuals:                      304
Method:                           MLE   Df Model:                            1
Date:                Fri, 15 Apr 2016   Pseudo R-squ.:                 0.01063
Time:                        09:40:27   Log-Likelihood:                -200.91
converged:                       True   LL-Null:                       -203.07
                                        LLR p-value:                   0.03773
==============================================================================
                 coef    std err          z      P>|z|      [95.0% Conf. Int.]
------------------------------------------------------------------------------
price         -0.2341      0.114     -2.058      0.040        -0.457    -0.011
intercept      2.4598      1.436      1.712      0.087        -0.356     5.275
==============================================================================

I'm not sure if a logistic regression would be the correct way to do this, but how would I maximize (not sure if im supposed to maximize anything though) the logistic function to determine what price would be the best price?

The optimal price would be defined where the total revenue is maximized, thus $E[R_i]=R_i⋅Pr(R_i)$ where $R_i$ would be the expected revenue of individ $i$ and $Pr(R_i)$ would be the probability of purchasing at that price. What would be the optimal price here?

$\endgroup$
2
  • 1
    $\begingroup$ This is not exactly what you want, but maybe closed enough. You could look at it as if you have run an A/B test with your customers, let's say for one of the groups you've kept the prices as they are, for others you've offered a discount. Then, you could use uplift modeling to predict the effect on lowering the price. From the results, you could do a cost/benefit analysis. You can use logistic regression for fitting the uplift. It is not even closed to what you want, but anyway, in case it helps. $\endgroup$
    – lrnzcig
    Commented Apr 21, 2016 at 17:46
  • 1
    $\begingroup$ @lrnzcig thanks for your comment, not exactly what I was after but still it is a good way to go and worth trying $\endgroup$ Commented Apr 26, 2016 at 10:56

3 Answers 3

3
$\begingroup$

Let $p$ be the price of the item and let $Q$ be the corresponding indicator of a sale (your quantity variable). Then your logistic regression can be specified as:

$$\mathbb{E}(Q) = \text{logistic}(\beta_0 + \beta_1 p).$$

Hence, the expected revenue at price $p$ is the unknown quantity:

$$\begin{equation} \begin{aligned} \bar{R}(p) \equiv \mathbb{E}(\text{Revenue}) &= p \cdot \mathbb{E}(Q) \\[6pt] &= p \cdot \text{logistic}(\beta_0 + \beta_1 p) \\[6pt] &= \frac{p}{1 + e^{-\beta_0 - \beta_1 p}}. \\[6pt] \end{aligned} \end{equation}$$

Note that this function involves unknown parameters $\beta_0$ and $\beta_1$ and so you cannot maximise it. Substituting the parameter estimates gives the predicted revenue:

$$\begin{equation} \begin{aligned} \hat{R}(p) \equiv \hat{\mathbb{E}}(\text{Revenue}) &= \frac{p}{1 + e^{-\hat{\beta}_0 - \hat{\beta}_1 p}}. \\[6pt] \end{aligned} \end{equation}$$

This latter function is known and can therefore be maximised via standard calculus techniques. In particular, it has first derivative:

$$\frac{d \hat{R}}{dp}(p) = \frac{1 + (1+\hat{\beta}_1 p) e^{-\hat{\beta}_0 - \hat{\beta}_1 p}}{(1 + e^{-\hat{\beta}_0 - \hat{\beta}_1 p})^2},$$

which leads to the critical point equation $1 + \hat{\beta}_1 \hat{p} = - e^{\hat{\beta}_0 + \hat{\beta}_1 \hat{p}}$. As Ingolifs correctly points out in another answer, solving this critical point equation uses the Lambert W function.

$\endgroup$
1
$\begingroup$

So you have the following functions describing your data: enter image description here

And you want the maximum of GLM result * price.

You have two approaches: 1. Solve analytically. You have an equation of the form $\frac{x}{1+e^{-(ax+b)}}$ where $a$ and $b$, according to your model, are -0.2341 and 2.45, respectively.

You can use calculus to find the optimum. It is a bit involved, however, as you will (I'm pretty sure, but could be wrong) need to use the Lambert W function.

The other alternative is to plot the values of $\frac{x}{1+e^{-(ax+b)}}$ from some range that contains the maximum, say, 1:100, and find the maximum value, and the price that gives the maximum value that way. It won't be exact, but you probably don't need exact.

$\endgroup$
0
$\begingroup$

Partially answered in comments:

This is not exactly what you want, but maybe closed enough. You could look at it as if you have run an A/B test with your customers, let's say for one of the groups you've kept the prices as they are, for others you've offered a discount. Then, you could use uplift modeling to predict the effect on lowering the price. From the results, you could do a cost/benefit analysis. You can use logistic regression for fitting the uplift. It is not even closed to what you want, but anyway, in case it helps. – lrnzcig

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.