diff --git a/09_optimal_pricing.Rmd b/09_optimal_pricing.Rmd index f7ec7a87..5f1c7d6c 100644 --- a/09_optimal_pricing.Rmd +++ b/09_optimal_pricing.Rmd @@ -16,11 +16,11 @@ using LaTeXStrings ## Overview -In a bayesian framework we can work intrinsically with the uncertainty of the data. It allows us to include it in our models. This is especially beneficial when we want to take a decision based on the results of a model. In this type of problem, if we optimize the expected value of the function we want to maximize, we obtain just a number, losing all the information and richness uncertainty can give us. +In a Bayesian framework we can work intrinsically with the uncertainty of the data. It allows us to include it in our models. This is especially beneficial when we want to make a decision based on the results of a model. In this type of problem, if we optimize the expected value of the function we want to maximize, we obtain just a number, losing all the information and richness uncertainty can give us. -In real-life scenarios, when making decisions we almost never have all the necessary information and therefore we have to deal with uncertainty. So it's important to be able to take into account how certain we are of the information we have. It may be the case that the value that maximizes (or minimize) certain problem comes with a lot of uncertainty so would be more appropriate to choose other with a better optimization-uncertainty trade off. +In real-life scenarios, when making decisions we almost never have all the necessary information and therefore we have to deal with uncertainty. So it's important to be able to take into account how certain we are of the information we have. It may be the case that the value that maximizes (or minimizes) certain problem comes with a lot of uncertainty so it would be more appropriate to choose other with a better optimization-uncertainty trade off. -Bayesian inference allows us to do this because of it approach of a statistical problem. From its point of view, the data obtained on an event is fixed. They are observations that have already happened and there is nothing stochastic about it. So the data is deterministic. +Bayesian inference allows us to do this because of its approach of a statistical problem. From its point of view, the data obtained on an event is fixed. They are observations that have already happened and there is nothing stochastic about it. So the data is deterministic. On the contrary, the parameters of the models we propose to describe such data are stochastic, following a given probability distribution. In this way, the inference that is made is on the complete distributions of our parameters, which allows us, precisely, to include the uncertainty into our models. @@ -31,11 +31,11 @@ Before starting we want to thank [Chad Scherrer](https://github.com/cscherrer) s --------------- Pricing a product is not an easy task. Multiple factors intervene in a customer's decision to buy a product. Also, a price can be fixed for some unknown business' decision. Now suppose you have a new product you want to introduce in the local market and you need to set a price for it. Also, as a businessman, you want to have the maximum profit. -If the kind of product you intend to produce were already in the market, you could use this information to have an initial guess. If the price is too high, you probably won't sell much. Conversely, if it’s too low, you probably sell more, but since the production process has an associate cost, you have to be careful and take it into account when you do the math. +If the kind of product you intend to produce were already in the market, you could use this information to have an initial guess. If the price is too high, you probably won't sell much. Conversely, if it’s too low, you probably sell more, but since the production process has an associated cost, you have to be careful and take it into account when you do the math. ### Price vs Quantity model -We are going to use a known equation to model the relationship between price of a product and the quantity demanded, the equation (1). The figure 1 shows its behavior for some value of *a* and *c*. This equation tell us that the higher the price, the less we sell, and if we continue rising the price, eventually our product it's so expensive that nobody is interested. +We are going to use a known equation to model the relationship between price of a product and the quantity demanded, the equation (1). The figure 1 shows its behavior for some value of *a* and *c*. This equation tells us that the higher the price, the less we sell, and if we continue raising the price, eventually our product it's so expensive that nobody is interested. ```{julia chap_9_plot_1} begin @@ -53,7 +53,7 @@ end You can imagine this as when you buy a luxury bread at the bakery: -In the beginning, if the price of this bread is very low and you will surely buy many of them, even giving some away so that others can try them. If one day you wake up and see that the price of this tasty bread is now double, you will surely stop buying too much and just concentrate on having it for a nice breakfast. Now, if a couple of months later the bakery became famous thanks to its delicious bread and they decided to sell it five times more expensive than before, you would start looking for another bakery. +In the beginning, if the price of this bread is very low, you will surely buy many of them, even giving some away so that others can try them. If one day you wake up and see that the price of this tasty bread is now double, you will surely stop buying too much and just concentrate on having it for a nice breakfast. Now, if a couple of months later the bakery became famous thanks to its delicious bread and they decided to sell it five times more expensive than before, you would start looking for another bakery. #### Power law distributions @@ -65,7 +65,7 @@ Surely many of you have the main idea: income is not distributed equally across In general, a few people concentrate most of the income, and only a little of the income is distributed in the majority of the population. The distributions that describe this phenomenon are called 'power laws'. The best known is perhaps the Pareto distribution or 80-20 distribution. A distribution widely used in business management referring to the fact that, for example, 20% of the mix of products sold are those that generate 80% of the profits. -In economics this idea is presented with the Lorentz curve: +In economics this idea is presented with the Lorenz curve: ```{julia chap_9_plot_2} begin @@ -87,14 +87,14 @@ w = exp.(randn(100)) f_vals, l_vals = lorenz(w) -plot(f_vals, label="Lorentz curve",l_vals, l=3,xlabel="Cumulative population", xaxis=0:0.1:1) +plot(f_vals, label="Lorenz curve",l_vals, l=3,xlabel="Cumulative population", xaxis=0:0.1:1) plot!(f_vals, label="Perfect equality", f_vals, l=3, ylabel="Cumulative income",yaxis=0:0.1:1) end ``` -*Lorentz curve. A graphical representation of income inequality.* +*Lorenz curve. A graphical representation of income inequality.* -In this graph, the x-axis represents the accumulated population and the y-axis the accumulated income. Going from left to right and as you move along the x-axis, more and more income is accumulated by fewer people. For example, the first 10% of the population barely accumulates 1% of income while the richest 10% on the right accumulates 40%. An ideal society with a perfectly distributed income would have a straight 45º Lorentz curve. +In this graph, the x-axis represents the accumulated population and the y-axis the accumulated income. Going from left to right and as you move along the x-axis, more and more income is accumulated by fewer people. For example, the first 10% of the population barely accumulates 1% of income while the richest 10% on the right accumulates 40%. An ideal society with a perfectly distributed income would have a straight 45º Lorenz curve. With this in mind we can already generate an intuition that will help us answer the initial question: why use a decreasing exponential and not a negative-slope line? @@ -168,7 +168,7 @@ In order to do this, an intelligent strategy is to linearize the relationship in $log(Q)=log(a) + clog(P)$ -Now, the only thing left to do is to define the model in a bayesian framework for Julia, called Turing, which is used to do probabilistic programming. +Now, the only thing left to do is to define the model in a Bayesian framework for Julia, called Turing, which is used to do probabilistic programming. ```{julia} @@ -207,11 +207,11 @@ Returning to the code. Julia allows us to easily define the variables that are p In addition, since the quantity of product sold is a discrete one and it comes from adding independent purchases, they are modeled as a poisson distribution. -But why do we subtract the mean for the price values? It´s a good practice to avoid a common problem: multicollinearity. With multicollinearity, the models tend to be more certain about the plausible values of our model, meanwhile models with more normalized data are more conservative and they are less prone to overfitting, an unwanted effect we need to avoid if we expect our model to work good with new. As a rule of thumb, it is always good to standardize our data. That is, subtract their average and divide each by its standard deviation. +But why do we subtract the mean for the price values? It's a good practice to avoid a common problem: multicollinearity. With multicollinearity, the models tend to be more certain about the plausible values of our model, meanwhile models with more normalized data are more conservative and they are less prone to overfitting, an unwanted effect we need to avoid if we expect our model to work good with new. As a rule of thumb, it is always good to standardize our data. That is, subtract their average and divide each by its standard deviation. #### Updating our beliefs -In our problem, we said we have already recorded some points of the curve for our product. And to do it we simply run the pilot test, fixing a price and counting the amount of product we sold. We can infer employing this data the “demand curve”, then we can propose a profit function for the new product and finally find the price that maximizes our profit. In the figure 2 we plot the points recorded in the pilot test. At first sight they seem to follow the expected relationship but it is not a perfect curve, right? They have some kind of "noise". Well, after all we could say that the reality is noisy. +In our problem, we said we have already recorded some points of the curve for our product. And to do it we simply run the pilot test, fixing a price and counting the amount of product we sold. We can infer employing this data the “demand curve”, then we can propose a profit function for the new product and finally find the price that maximizes our profit. In figure 2 we plot the points recorded in the pilot test. At first sight they seem to follow the expected relationship but it is not a perfect curve, right? They have some kind of "noise". Well, after all we could say that the reality is noisy. ```{julia chap_9_plot_6} begin @@ -225,9 +225,9 @@ begin end ``` -As we said, in a bayesian framework our previous knowledge are the distributions we propose for each of the parameters and the relationship known between price and quantity. +As we said, in a Bayesian framework our previous knowledge are the distributions we propose for each of the parameters and the relationship known between price and quantity. -With this bayesian approach, our previous knowledge are the distributions we propose for each of the parameters and the relationship known between price and quantity. What we do now is to update our believes, incorporating in our model the data points we have recoded from our pilot test as show in the code bellow, instantiating our model with the points *Quantity* and *Price*. Our model now has computed what is called the *posterior distributions* for the parameters *log a* and *c*, our updated beliefs for the plausible values for this two parameters. +With this Bayesian approach, our previous knowledge are the distributions we propose for each of the parameters and the relationship known between price and quantity. What we do now is to update our believes, incorporating in our model the data points we have recorded from our pilot test as show in the code bellow, instantiating our model with the points *Quantity* and *Price*. Our model now has computed what is called the *posterior distributions* for the parameters *log a* and *c*, our updated beliefs for the plausible values for this two parameters. ```{julia,results = FALSE} begin @@ -248,7 +248,7 @@ end ``` *Posterior distributions for the parameters log a and c.* -Let's stop for a moment and analyze this. We defined our model and asked turing to return the best possible estimate of our parameters, taking into account our initial beliefs and the information obtained from the pilot test, and what Turing returns was a distribution of possibilities for those parameters. +Let's stop for a moment and analyze this. We defined our model and asked Turing to return the best possible estimate of our parameters, taking into account our initial beliefs and the information obtained from the pilot test, and what Turing returned was a distribution of possibilities for those parameters. But, our model is defined by a single value of a and c. So what do we do? One option would be to take the mean of our distributions. @@ -282,7 +282,7 @@ end end ``` -Here we are creating an array of as many rows as price values we want to observe and with as many columns as samples we have of each of our log and c parameters, that is, as many columns as models we have at our disposal. Let´s plot them all and se what happen: +Here we are creating an array of as many rows as price values we want to observe and with as many columns as samples we have of each of our log and c parameters, that is, as many columns as models we have at our disposal. Let's plot them all and see what happen: ```{julia chap_9_plot_8} begin @@ -301,7 +301,7 @@ In this way we can visualize all the possible models that our Bayesian inference As a last check (even if we have already taken preventive measures), we want to make sure that our model parameters do not share information. That is, we want to check that there is no collinearity between them. -To evaluate multicollinearity between the two parameters of our model, we plot the sampled values, one against the other. In the figure 4, we don't see a pattern, they seem to be decorrelated, therefore multicollinearity is not present in our model, so we are good to go and we can continue with the problem. +To evaluate multicollinearity between the two parameters of our model, we plot the sampled values, one against the other. In figure 4, we don't see a pattern, they seem to be decorrelated, therefore multicollinearity is not present in our model, so we are good to go and we can continue with the problem. ```{julia chap_9_plot_9} begin @@ -321,7 +321,7 @@ Now that we have estimated our posterior distributions, we will try to answer th This is why we calculated the relationship between the price and the quantity of our product. As we said before, depending on that relation, it was going to be possible to define an optimal price point. Now we only have to add one more part to the equation: the production costs. -Having this, we will be able to set up our profit function that will tell us, for each price we choose, how much money we would expect to earn. So let´s define it: +Having this, we will be able to set up our profit function that will tell us, for each price we choose, how much money we would expect to earn. So let's define it: As many of you know, the profit on the sale of a product is calculated as income minus costs. @@ -390,7 +390,7 @@ Then, analyzing the graph: The red line plotted is the mean expected profit and its maximum is near $4840. The region between the orange lines is approximately one standard deviation far from the expected value or where the 65% of the lines, plotted from the sampled values of our parameters, fall. -With this in mind and seeing that the profit curve is quite flat in the sector where the maximum is found, one could argue that it is preferable to choose a lower price since since the money lost would be minimal, but the volatility would go down considerably. +With this in mind and seeing that the profit curve is quite flat in the sector where the maximum is found, one could argue that it is preferable to choose a lower price since the money lost would be minimal, but the volatility would go down considerably. In order to see this, it would be interesting to graph the standard deviation of the profit according to the price we choose: @@ -468,13 +468,13 @@ porcentual_std_diff = ( unfav_4000 - unfav) / unfav *100 So, for every dollar we "lost" in average profitability, we gained more than double in the reduction of uncertainty. -Regardless of each person decision, the important thing about the Bayesian framework is that it allows us to include uncertainty in our models and use it to our advantage to make more informed and intelligent decisions. +Regardless of each person's decision, the important thing about the Bayesian framework is that it allows us to include uncertainty in our models and use it to our advantage to make more informed and intelligent decisions. Instead of wanting to forget and get rid of uncertainty, Bayesianism allows us to accept that this is an inherent feature of reality and to take advantage of it. Being able to narrow down how sure we are about the inferences we make gives us an invaluable advantage when making decisions. ## Summary -In this chapter we have learned some basics concepts of economics such as the price elasticity of demand for a product, or the Pareto distribution of income and wealth. Then, we estimated the demand curve of a possible new product, performing a pilot test to see the relationship between price and quantity demanded. Thanks to Bayesian inference we were able to use the uncertainty we had to our advantage, quantifying the trade-off between expected return and the variability of it, making possible to perform a well informed decision. +In this chapter we have learned some basic concepts of economics such as the price elasticity of demand for a product, or the Pareto distribution of income and wealth. Then, we estimated the demand curve of a possible new product, performing a pilot test to see the relationship between price and quantity demanded. Thanks to Bayesian inference we were able to use the uncertainty we had to our advantage, quantifying the trade-off between expected return and the variability of it, making possible to perform a well informed decision. ## References diff --git a/09_optimal_pricing/09_optimal_pricing.jl b/09_optimal_pricing/09_optimal_pricing.jl index c869f6be..c1daa0ba 100644 --- a/09_optimal_pricing/09_optimal_pricing.jl +++ b/09_optimal_pricing/09_optimal_pricing.jl @@ -40,11 +40,11 @@ We are currently working on: # ╔═╡ 5f171c4c-1567-11eb-0d69-f116e79738b5 md"# Overview -In a bayesian framework we can work intrinsically with the uncertainty of the data. It allows us to include it in our models. This is especially beneficial when we want to take a decision based on the results of a model. In this type of problem, if we optimize the expected value of the function we want to maximize, we obtain just a number, losing all the information and richness uncertainty can give us. +In a bayesian framework we can work intrinsically with the uncertainty of the data. It allows us to include it in our models. This is especially beneficial when we want to make a decision based on the results of a model. In this type of problem, if we optimize the expected value of the function we want to maximize, we obtain just a number, losing all the information and richness uncertainty can give us. -In real-life scenarios, when making decisions we almost never have all the necessary information and therefore we have to deal with uncertainty. So it's important to be able to take into account how certain we are of the information we have. It may be the case that the value that maximizes (or minimize) certain problem comes with a lot of uncertainty so would be more appropriate to choose other with a better optimization-uncertainty trade off. +In real-life scenarios, when making decisions we almost never have all the necessary information and therefore we have to deal with uncertainty. So it's important to be able to take into account how certain we are of the information we have. It may be the case that the value that maximizes (or minimizes) certain problem comes with a lot of uncertainty so it would be more appropriate to choose other with a better optimization-uncertainty trade off. -Bayesian inference allows us to do this because of it approach of a statistical problem. From its point of view, the data obtained on an event is fixed. They are observations that have already happened and there is nothing stochastic about it. So the data is deterministic. +Bayesian inference allows us to do this because of its approach of a statistical problem. From its point of view, the data obtained on an event is fixed. They are observations that have already happened and there is nothing stochastic about it. So the data is deterministic. On the contrary, the parameters of the models we propose to describe such data are stochastic, following a given probability distribution. In this way, the inference that is made is on the complete distributions of our parameters, which allows us, precisely, to include the uncertainty into our models." @@ -54,16 +54,16 @@ md"## Optimal pricing --------------- Pricing a product is not an easy task. Multiple factors intervene in a customer's decision to buy a product. Also, a price can be fixed for some unknown business' decision. Now suppose you have a new product you want to introduce in the local market and you need to set a price for it. Also, as a businessman, you want to have the maximum profit. -If the kind of product you intend to produce were already in the market, you could use this information to have an initial guess. If the price is too high, you probably won't sell much. Conversely, if it’s too low, you probably sell more, but since the production process has an associate cost, you have to be careful and take it into account when you do the math. +If the kind of product you intend to produce were already in the market, you could use this information to have an initial guess. If the price is too high, you probably won't sell much. Conversely, if it’s too low, you probably sell more, but since the production process has an associated cost, you have to be careful and take it into account when you do the math. ### Price vs Quantity model -We are going to use a known equation to model the relationship between price of a product and the quantity demanded, the equation (1). The figure 1 shows its behavior for some value of *a* and *c*. This equation tell us that the higher the price, the less we sell, and if we continue rising the price, eventually our product it's so expensive that nobody is interested." +We are going to use a known equation to model the relationship between price of a product and the quantity demanded, the equation (1). The figure 1 shows its behavior for some value of *a* and *c*. This equation tells us that the higher the price, the less we sell, and if we continue raising the price, eventually our product it's so expensive that nobody is interested." # ╔═╡ 821ba35e-1568-11eb-3a08-f988ebc1b1e3 md"You can imagine this as when you buy a luxury bread at the bakery: -In the beginning, if the price of this bread is very low and you will surely buy many of them, even giving some away so that others can try them. If one day you wake up and see that the price of this tasty bread is now double, you will surely stop buying too much and just concentrate on having it for a nice breakfast. Now, if a couple of months later the bakery became famous thanks to its delicious bread and they decided to sell it five times more expensive than before, you would start looking for another bakery. +In the beginning, if the price of this bread is very low, you will surely buy many of them, even giving some away so that others can try them. If one day you wake up and see that the price of this tasty bread is now double, you will surely stop buying too much and just concentrate on having it for a nice breakfast. Now, if a couple of months later the bakery became famous thanks to its delicious bread and they decided to sell it five times more expensive than before, you would start looking for another bakery. #### Power law distributions @@ -75,7 +75,7 @@ Surely many of you have the main idea: income is not distributed equally across In general, a few people concentrate most of the income, and only a little of the income is distributed in the majority of the population. The distributions that describe this phenomenon are called 'power laws'. The best known is perhaps the Pareto distribution or 80-20 distribution. A distribution widely used in business management referring to the fact that, for example, 20% of the mix of products sold are those that generate 80% of the profits. -In economics this idea is presented with the Lorentz curve:" +In economics this idea is presented with the Lorenz curve:" # ╔═╡ c8cbd94e-1569-11eb-27b2-513b849460eb begin @@ -97,15 +97,15 @@ w = exp.(randn(100)) f_vals, l_vals = lorenz(w) -plot(f_vals, label="Lorentz curve",l_vals, l=3,xlabel="Cumulative population", xaxis=0:0.1:1) +plot(f_vals, label="Lorenz curve",l_vals, l=3,xlabel="Cumulative population", xaxis=0:0.1:1) plot!(f_vals, label="Perfect equality", f_vals, l=3, ylabel="Cumulative income",yaxis=0:0.1:1) end # ╔═╡ 0d3fe04c-1570-11eb-2fd7-c5a366cbc13f -md"*Lorentz curve. A graphical representation of income inequality.*" +md"*Lorenz curve. A graphical representation of income inequality.*" # ╔═╡ 1247d9d6-156a-11eb-35d2-d9264c933280 -md"In this graph, the x-axis represents the accumulated population and the y-axis the accumulated income. Going from left to right and as you move along the x-axis, more and more income is accumulated by fewer people. For example, the first 10% of the population barely accumulates 1% of income while the richest 10% on the right accumulates 40%. An ideal society with a perfectly distributed income would have a straight 45º Lorentz curve. +md"In this graph, the x-axis represents the accumulated population and the y-axis the accumulated income. Going from left to right and as you move along the x-axis, more and more income is accumulated by fewer people. For example, the first 10% of the population barely accumulates 1% of income while the richest 10% on the right accumulates 40%. An ideal society with a perfectly distributed income would have a straight 45º Lorenz curve. With this in mind we can already generate an intuition that will help us answer the initial question: why use a decreasing exponential and not a negative-slope line? @@ -222,11 +222,11 @@ Returning to the code. Julia allows us to easily define the variables that are p In addition, since the quantity of product sold is a discrete one and it comes from adding independent purchases, they are modeled as a poisson distribution. -But why do we subtract the mean for the price values? It´s a good practice to avoid a common problem: multicollinearity. With multicollinearity, the models tend to be more certain about the plausible values of our model, meanwhile models with more normalized data are more conservative and they are less prone to overfitting, an unwanted effect we need to avoid if we expect our model to work good with new. As a rule of thumb, it is always good to standardize our data. That is, subtract their average and divide each by its standard deviation. +But why do we subtract the mean for the price values? It's a good practice to avoid a common problem: multicollinearity. With multicollinearity, the models tend to be more certain about the plausible values of our model, meanwhile models with more normalized data are more conservative and they are less prone to overfitting, an unwanted effect we need to avoid if we expect our model to work good with new. As a rule of thumb, it is always good to standardize our data. That is, subtract their average and divide each by its standard deviation. #### Updating our beliefs -In our problem, we said we have already recorded some points of the curve for our product. And to do it we simply run the pilot test, fixing a price and counting the amount of product we sold. We can infer employing this data the “demand curve”, then we can propose a profit function for the new product and finally find the price that maximizes our profit. In the figure 2 we plot the points recorded in the pilot test. At first sight they seem to follow the expected relationship but it is not a perfect curve, right? They have some kind of "noise". Well, after all we could say that the reality is noisy.""" +In our problem, we said we have already recorded some points of the curve for our product. And to do it we simply run the pilot test, fixing a price and counting the amount of product we sold. We can infer employing this data the “demand curve”, then we can propose a profit function for the new product and finally find the price that maximizes our profit. In figure 2 we plot the points recorded in the pilot test. At first sight they seem to follow the expected relationship but it is not a perfect curve, right? They have some kind of "noise". Well, after all we could say that the reality is noisy.""" # ╔═╡ 785a8984-1570-11eb-3b51-131d970de8d3 begin @@ -264,7 +264,7 @@ end md"*Posterior distributions for the parameters log a and c.*" # ╔═╡ 02207a56-1574-11eb-0436-67fe6b08448d -md"Let's stop for a moment and analyze this. We defined our model and asked turing to return the best possible estimate of our parameters, taking into account our initial beliefs and the information obtained from the pilot test, and what Turing returns was a distribution of possibilities for those parameters. +md"Let's stop for a moment and analyze this. We defined our model and asked Turing to return the best possible estimate of our parameters, taking into account our initial beliefs and the information obtained from the pilot test, and what Turing returned was a distribution of possibilities for those parameters. But, our model is defined by a single value of a and c. So what do we do? One option would be to take the mean of our distributions." @@ -298,7 +298,7 @@ end end # ╔═╡ 7cf67c6e-1574-11eb-3953-cd88073b6879 -md"Here we are creating an array of as many rows as price values we want to observe and with as many columns as samples we have of each of our log and c parameters, that is, as many columns as models we have at our disposal. Let´s plot them all and se what happen:" +md"Here we are creating an array of as many rows as price values we want to observe and with as many columns as samples we have of each of our log and c parameters, that is, as many columns as models we have at our disposal. Let's plot them all and see what happen:" # ╔═╡ 855ae83e-1574-11eb-2b2a-5b6371a7f110 begin @@ -317,7 +317,7 @@ md"In this way we can visualize all the possible models that our Bayesian infere As a last check (even if we have already taken preventive measures), we want to make sure that our model parameters do not share information. That is, we want to check that there is no collinearity between them. -To evaluate multicollinearity between the two parameters of our model, we plot the sampled values, one against the other. In the figure 4, we don't see a pattern, they seem to be decorrelated, therefore multicollinearity is not present in our model, so we are good to go and we can continue with the problem." +To evaluate multicollinearity between the two parameters of our model, we plot the sampled values, one against the other. In figure 4, we don't see a pattern, they seem to be decorrelated, therefore multicollinearity is not present in our model, so we are good to go and we can continue with the problem." # ╔═╡ b758edd6-1574-11eb-2fe3-218ddec7fd26 begin @@ -338,7 +338,7 @@ Now that we have estimated our posterior distributions, we will try to answer th This is why we calculated the relationship between the price and the quantity of our product. As we said before, depending on that relation, it was going to be possible to define an optimal price point. Now we only have to add one more part to the equation: the production costs. -Having this, we will be able to set up our profit function that will tell us, for each price we choose, how much money we would expect to earn. So let´s define it: +Having this, we will be able to set up our profit function that will tell us, for each price we choose, how much money we would expect to earn. So let's define it: As many of you know, the profit on the sale of a product is calculated as income minus costs. @@ -408,7 +408,7 @@ Then, analyzing the graph: The red line plotted is the mean expected profit and its maximum is near $4840. The region between the orange lines is approximately one standard deviation far from the expected value or where the 65% of the lines, plotted from the sampled values of our parameters, fall. -With this in mind and seeing that the profit curve is quite flat in the sector where the maximum is found, one could argue that it is preferable to choose a lower price since since the money lost would be minimal, but the volatility would go down considerably. +With this in mind and seeing that the profit curve is quite flat in the sector where the maximum is found, one could argue that it is preferable to choose a lower price since the money lost would be minimal, but the volatility would go down considerably. In order to see this, it would be interesting to graph the standard deviation of the profit according to the price we choose: " @@ -482,13 +482,13 @@ porcentual_std_diff = ( unfav_4000 - unfav) / unfav *100 # ╔═╡ 32997ca8-1869-11eb-2bc6-11da0327e0b8 md"""So, for every dollar we "lost" in average profitability, we gained more than double in the reduction of uncertainty. -Regardless of each person decision, the important thing about the Bayesian framework is that it allows us to include uncertainty in our models and use it to our advantage to make more informed and intelligent decisions. +Regardless of each person's decision, the important thing about the Bayesian framework is that it allows us to include uncertainty in our models and use it to our advantage to make more informed and intelligent decisions. Instead of wanting to forget and get rid of uncertainty, Bayesianism allows us to accept that this is an inherent feature of reality and to take advantage of it. Being able to narrow down how sure we are about the inferences we make gives us an invaluable advantage when making decisions. ### Summary -In this chapter we have learned some basics concepts of economics such as the price elasticity of demand for a product, or the Pareto distribution of income and wealth. Then, we estimated the demand curve of a possible new product, performing a pilot test to see the relationship between price and quantity demanded. Thanks to Bayesian inference we were able to use the uncertainty we had to our advantage, quantifying the trade-off between expected return and the variability of it, making possible to perform a well informed decision. +In this chapter we have learned some basic concepts of economics such as the price elasticity of demand for a product, or the Pareto distribution of income and wealth. Then, we estimated the demand curve of a possible new product, performing a pilot test to see the relationship between price and quantity demanded. Thanks to Bayesian inference we were able to use the uncertainty we had to our advantage, quantifying the trade-off between expected return and the variability of it, making possible to perform a well informed decision. """ # ╔═╡ 03117e4c-5b65-11eb-2973-6f2eaf3d9199 diff --git a/docs/data_science_in_julia_for_hackers_files/figure-html/chap_9_plot_10-J1.png b/docs/data_science_in_julia_for_hackers_files/figure-html/chap_9_plot_10-J1.png index bbb36d12..a5993e3a 100644 Binary files a/docs/data_science_in_julia_for_hackers_files/figure-html/chap_9_plot_10-J1.png and b/docs/data_science_in_julia_for_hackers_files/figure-html/chap_9_plot_10-J1.png differ diff --git a/docs/data_science_in_julia_for_hackers_files/figure-html/chap_9_plot_11-J1.png b/docs/data_science_in_julia_for_hackers_files/figure-html/chap_9_plot_11-J1.png index 6644be7f..ec61e76d 100644 Binary files a/docs/data_science_in_julia_for_hackers_files/figure-html/chap_9_plot_11-J1.png and b/docs/data_science_in_julia_for_hackers_files/figure-html/chap_9_plot_11-J1.png differ diff --git a/docs/data_science_in_julia_for_hackers_files/figure-html/chap_9_plot_12-J1.png b/docs/data_science_in_julia_for_hackers_files/figure-html/chap_9_plot_12-J1.png index d4bba991..70b55b91 100644 Binary files a/docs/data_science_in_julia_for_hackers_files/figure-html/chap_9_plot_12-J1.png and b/docs/data_science_in_julia_for_hackers_files/figure-html/chap_9_plot_12-J1.png differ diff --git a/docs/data_science_in_julia_for_hackers_files/figure-html/chap_9_plot_2-J1.png b/docs/data_science_in_julia_for_hackers_files/figure-html/chap_9_plot_2-J1.png index ede09629..5ccc8dbb 100644 Binary files a/docs/data_science_in_julia_for_hackers_files/figure-html/chap_9_plot_2-J1.png and b/docs/data_science_in_julia_for_hackers_files/figure-html/chap_9_plot_2-J1.png differ diff --git a/docs/data_science_in_julia_for_hackers_files/figure-html/chap_9_plot_7-J1.png b/docs/data_science_in_julia_for_hackers_files/figure-html/chap_9_plot_7-J1.png index 0e33611a..246e1797 100644 Binary files a/docs/data_science_in_julia_for_hackers_files/figure-html/chap_9_plot_7-J1.png and b/docs/data_science_in_julia_for_hackers_files/figure-html/chap_9_plot_7-J1.png differ diff --git a/docs/data_science_in_julia_for_hackers_files/figure-html/chap_9_plot_8-J1.png b/docs/data_science_in_julia_for_hackers_files/figure-html/chap_9_plot_8-J1.png index c6b889dc..9464eafe 100644 Binary files a/docs/data_science_in_julia_for_hackers_files/figure-html/chap_9_plot_8-J1.png and b/docs/data_science_in_julia_for_hackers_files/figure-html/chap_9_plot_8-J1.png differ diff --git a/docs/data_science_in_julia_for_hackers_files/figure-html/chap_9_plot_9-J1.png b/docs/data_science_in_julia_for_hackers_files/figure-html/chap_9_plot_9-J1.png index 1e42f53b..6a09412e 100644 Binary files a/docs/data_science_in_julia_for_hackers_files/figure-html/chap_9_plot_9-J1.png and b/docs/data_science_in_julia_for_hackers_files/figure-html/chap_9_plot_9-J1.png differ diff --git a/docs/optimal-pricing.html b/docs/optimal-pricing.html index 7c842fab..58c3d642 100644 --- a/docs/optimal-pricing.html +++ b/docs/optimal-pricing.html @@ -279,7 +279,7 @@
  • Published with bookdown
  • - + @@ -311,9 +311,9 @@

    Chapter 9 Optimal pricing

    using LaTeXStrings

    9.1 Overview

    -

    In a bayesian framework we can work intrinsically with the uncertainty of the data. It allows us to include it in our models. This is especially beneficial when we want to take a decision based on the results of a model. In this type of problem, if we optimize the expected value of the function we want to maximize, we obtain just a number, losing all the information and richness uncertainty can give us.

    -

    In real-life scenarios, when making decisions we almost never have all the necessary information and therefore we have to deal with uncertainty. So it’s important to be able to take into account how certain we are of the information we have. It may be the case that the value that maximizes (or minimize) certain problem comes with a lot of uncertainty so would be more appropriate to choose other with a better optimization-uncertainty trade off.

    -

    Bayesian inference allows us to do this because of it approach of a statistical problem. From its point of view, the data obtained on an event is fixed. They are observations that have already happened and there is nothing stochastic about it. So the data is deterministic.

    +

    In a Bayesian framework we can work intrinsically with the uncertainty of the data. It allows us to include it in our models. This is especially beneficial when we want to make a decision based on the results of a model. In this type of problem, if we optimize the expected value of the function we want to maximize, we obtain just a number, losing all the information and richness uncertainty can give us.

    +

    In real-life scenarios, when making decisions we almost never have all the necessary information and therefore we have to deal with uncertainty. So it’s important to be able to take into account how certain we are of the information we have. It may be the case that the value that maximizes (or minimizes) certain problem comes with a lot of uncertainty so it would be more appropriate to choose other with a better optimization-uncertainty trade off.

    +

    Bayesian inference allows us to do this because of its approach of a statistical problem. From its point of view, the data obtained on an event is fixed. They are observations that have already happened and there is nothing stochastic about it. So the data is deterministic.

    On the contrary, the parameters of the models we propose to describe such data are stochastic, following a given probability distribution. In this way, the inference that is made is on the complete distributions of our parameters, which allows us, precisely, to include the uncertainty into our models.

    Before starting we want to thank Chad Scherrer since this chapter is inspired by his article"

    @@ -321,10 +321,10 @@

    9.1 Overview

    9.2 Optimal pricing


    Pricing a product is not an easy task. Multiple factors intervene in a customer’s decision to buy a product. Also, a price can be fixed for some unknown business’ decision. Now suppose you have a new product you want to introduce in the local market and you need to set a price for it. Also, as a businessman, you want to have the maximum profit.

    -

    If the kind of product you intend to produce were already in the market, you could use this information to have an initial guess. If the price is too high, you probably won’t sell much. Conversely, if it’s too low, you probably sell more, but since the production process has an associate cost, you have to be careful and take it into account when you do the math.

    +

    If the kind of product you intend to produce were already in the market, you could use this information to have an initial guess. If the price is too high, you probably won’t sell much. Conversely, if it’s too low, you probably sell more, but since the production process has an associated cost, you have to be careful and take it into account when you do the math.

    9.2.1 Price vs Quantity model

    -

    We are going to use a known equation to model the relationship between price of a product and the quantity demanded, the equation (1). The figure 1 shows its behavior for some value of a and c. This equation tell us that the higher the price, the less we sell, and if we continue rising the price, eventually our product it’s so expensive that nobody is interested.

    +

    We are going to use a known equation to model the relationship between price of a product and the quantity demanded, the equation (1). The figure 1 shows its behavior for some value of a and c. This equation tells us that the higher the price, the less we sell, and if we continue raising the price, eventually our product it’s so expensive that nobody is interested.

    begin
     
     a_ = 5000
    @@ -338,14 +338,14 @@ 

    9.2.1 Price vs Quantity model

    end

    You can imagine this as when you buy a luxury bread at the bakery:

    -

    In the beginning, if the price of this bread is very low and you will surely buy many of them, even giving some away so that others can try them. If one day you wake up and see that the price of this tasty bread is now double, you will surely stop buying too much and just concentrate on having it for a nice breakfast. Now, if a couple of months later the bakery became famous thanks to its delicious bread and they decided to sell it five times more expensive than before, you would start looking for another bakery.

    +

    In the beginning, if the price of this bread is very low, you will surely buy many of them, even giving some away so that others can try them. If one day you wake up and see that the price of this tasty bread is now double, you will surely stop buying too much and just concentrate on having it for a nice breakfast. Now, if a couple of months later the bakery became famous thanks to its delicious bread and they decided to sell it five times more expensive than before, you would start looking for another bakery.

    9.2.1.1 Power law distributions

    Okay, so we agree that our model has to express that as the price goes up the quantity tends to go down. However, one could ask why use a decreasing exponential function and not another one, for example a linear relationship with a negative slope.

    The answer to this question is not straightforward. To start building an intuition, we must think about how people’s income is distributed.

    Surely many of you have the main idea: income is not distributed equally across the population.

    In general, a few people concentrate most of the income, and only a little of the income is distributed in the majority of the population. The distributions that describe this phenomenon are called ‘power laws.’ The best known is perhaps the Pareto distribution or 80-20 distribution. A distribution widely used in business management referring to the fact that, for example, 20% of the mix of products sold are those that generate 80% of the profits.

    -

    In economics this idea is presented with the Lorentz curve:

    +

    In economics this idea is presented with the Lorenz curve:

    begin
     function lorenz(y)  
         n = length(y)
    @@ -365,12 +365,12 @@ 

    9.2.1.1 Power law distributions f_vals, l_vals = lorenz(w) -plot(f_vals, label="Lorentz curve",l_vals, l=3,xlabel="Cumulative population", xaxis=0:0.1:1) +plot(f_vals, label="Lorenz curve",l_vals, l=3,xlabel="Cumulative population", xaxis=0:0.1:1) plot!(f_vals, label="Perfect equality", f_vals, l=3, ylabel="Cumulative income",yaxis=0:0.1:1) end

    -

    Lorentz curve. A graphical representation of income inequality.

    -

    In this graph, the x-axis represents the accumulated population and the y-axis the accumulated income. Going from left to right and as you move along the x-axis, more and more income is accumulated by fewer people. For example, the first 10% of the population barely accumulates 1% of income while the richest 10% on the right accumulates 40%. An ideal society with a perfectly distributed income would have a straight 45º Lorentz curve.

    +

    Lorenz curve. A graphical representation of income inequality.

    +

    In this graph, the x-axis represents the accumulated population and the y-axis the accumulated income. Going from left to right and as you move along the x-axis, more and more income is accumulated by fewer people. For example, the first 10% of the population barely accumulates 1% of income while the richest 10% on the right accumulates 40%. An ideal society with a perfectly distributed income would have a straight 45º Lorenz curve.

    With this in mind we can already generate an intuition that will help us answer the initial question: why use a decreasing exponential and not a negative-slope line?

    Well, since a great majority of people have a small relative income and a minority has a large one, as we increase the price of the product, a large number of people with low income can no longer afford it. This process continues until only people with a high income are left and their consumption preferences are not greatly affected by the price increase.

    The exponential distribution is useful to describe this.

    @@ -421,7 +421,7 @@

    9.2.2.1 Dealing with uncertanty\(Q = aP^{c}\)

    In order to do this, an intelligent strategy is to linearize the relationship in order to perform a simple linear regression. Simply taking the logarithm of both sides of the equation achieves the goal:

    \(log(Q)=log(a) + clog(P)\)

    -

    Now, the only thing left to do is to define the model in a bayesian framework for Julia, called Turing, which is used to do probabilistic programming.

    +

    Now, the only thing left to do is to define the model in a Bayesian framework for Julia, called Turing, which is used to do probabilistic programming.

    begin
         @model function quantity(qval,p0)
         loga ~ Cauchy()
    @@ -449,11 +449,11 @@ 

    9.2.2.2 Priors: our previous know

    Another very important use of priors is to define the scale of the problem. In the example of height and weight it would be useful to say something like ‘It doesn’t make sense that for every additional kilogram of weight, a person will measure one meter more. At most a few centimeters.’ All this information can be communicated to our model through the priors we choose. Let’s leave it there for now.

    Returning to the code. Julia allows us to easily define the variables that are probability distributions using the ~ operator. Once we know c and log a for a given value of price, we can univocally determine the quantity, therefore the variables \(\log(\mu_0)\) (and \(\mu_0\)) are defined with the = operator, indicating a deterministic relation.

    In addition, since the quantity of product sold is a discrete one and it comes from adding independent purchases, they are modeled as a poisson distribution.

    -

    But why do we subtract the mean for the price values? It´s a good practice to avoid a common problem: multicollinearity. With multicollinearity, the models tend to be more certain about the plausible values of our model, meanwhile models with more normalized data are more conservative and they are less prone to overfitting, an unwanted effect we need to avoid if we expect our model to work good with new. As a rule of thumb, it is always good to standardize our data. That is, subtract their average and divide each by its standard deviation.

    +

    But why do we subtract the mean for the price values? It’s a good practice to avoid a common problem: multicollinearity. With multicollinearity, the models tend to be more certain about the plausible values of our model, meanwhile models with more normalized data are more conservative and they are less prone to overfitting, an unwanted effect we need to avoid if we expect our model to work good with new. As a rule of thumb, it is always good to standardize our data. That is, subtract their average and divide each by its standard deviation.

    9.2.2.3 Updating our beliefs

    -

    In our problem, we said we have already recorded some points of the curve for our product. And to do it we simply run the pilot test, fixing a price and counting the amount of product we sold. We can infer employing this data the “demand curve,” then we can propose a profit function for the new product and finally find the price that maximizes our profit. In the figure 2 we plot the points recorded in the pilot test. At first sight they seem to follow the expected relationship but it is not a perfect curve, right? They have some kind of “noise.” Well, after all we could say that the reality is noisy.

    +

    In our problem, we said we have already recorded some points of the curve for our product. And to do it we simply run the pilot test, fixing a price and counting the amount of product we sold. We can infer employing this data the “demand curve,” then we can propose a profit function for the new product and finally find the price that maximizes our profit. In figure 2 we plot the points recorded in the pilot test. At first sight they seem to follow the expected relationship but it is not a perfect curve, right? They have some kind of “noise.” Well, after all we could say that the reality is noisy.

    begin
         #Our points from the pilot test
         Price = [1500, 2500, 4000, 5000] 
    @@ -464,8 +464,8 @@ 

    9.2.2.3 Updating our beliefs

    ylabel!("Quantity") end

    -

    As we said, in a bayesian framework our previous knowledge are the distributions we propose for each of the parameters and the relationship known between price and quantity.

    -

    With this bayesian approach, our previous knowledge are the distributions we propose for each of the parameters and the relationship known between price and quantity. What we do now is to update our believes, incorporating in our model the data points we have recoded from our pilot test as show in the code bellow, instantiating our model with the points Quantity and Price. Our model now has computed what is called the posterior distributions for the parameters log a and c, our updated beliefs for the plausible values for this two parameters.

    +

    As we said, in a Bayesian framework our previous knowledge are the distributions we propose for each of the parameters and the relationship known between price and quantity.

    +

    With this Bayesian approach, our previous knowledge are the distributions we propose for each of the parameters and the relationship known between price and quantity. What we do now is to update our believes, incorporating in our model the data points we have recorded from our pilot test as show in the code bellow, instantiating our model with the points Quantity and Price. Our model now has computed what is called the posterior distributions for the parameters log a and c, our updated beliefs for the plausible values for this two parameters.

    begin
         model = quantity(Quantity, Price)
         posterior = sample(model, NUTS(),1000)
    @@ -480,12 +480,12 @@ 

    9.2.2.3 Updating our beliefs

    end

    Posterior distributions for the parameters log a and c. -Let’s stop for a moment and analyze this. We defined our model and asked turing to return the best possible estimate of our parameters, taking into account our initial beliefs and the information obtained from the pilot test, and what Turing returns was a distribution of possibilities for those parameters.

    +Let’s stop for a moment and analyze this. We defined our model and asked Turing to return the best possible estimate of our parameters, taking into account our initial beliefs and the information obtained from the pilot test, and what Turing returned was a distribution of possibilities for those parameters.

    But, our model is defined by a single value of a and c. So what do we do? One option would be to take the mean of our distributions.

    mean(post_loga[1])
    -
    ## 5.5460012328826735
    +
    ## 5.546444583138311
    mean(post_c[1])
    -
    ## -1.1838279679326476
    +
    ## -1.1808080259045772

    So Log(a) would be 5.55 and c -1.18, and we should only have to replace those values in our model equation to get the answer to our problem:

    $ Log(Q)=5.55 - 1.18Log(P) $

    This would make sense? Not even close. By doing this we would be throwing away a lot of precious information that the Bayesian framework gives us: The uncertainty about our inference.

    @@ -501,7 +501,7 @@

    9.2.2.4 Making uncertainty our al q[:,i] = exp.(post_loga[1][i] .+ post_c[1][i] .* (log.(p) .- mean(log.(Price)))) end end

    -

    Here we are creating an array of as many rows as price values we want to observe and with as many columns as samples we have of each of our log and c parameters, that is, as many columns as models we have at our disposal. Let´s plot them all and se what happen:

    +

    Here we are creating an array of as many rows as price values we want to observe and with as many columns as samples we have of each of our log and c parameters, that is, as many columns as models we have at our disposal. Let’s plot them all and see what happen:

    begin
         plot(p,q[:,1], xlim=(1000,6000))
         for i in collect(1:length(post_c[1]))
    @@ -515,7 +515,7 @@ 

    9.2.2.4 Making uncertainty our al

    In this way we can visualize all the possible models that our Bayesian inference gives us. Since values of log a and c with higher probability will be sampled more often, the density of lines give us a sense of plausibility, and therefore we can evaluate the certainty (or uncertainty) of our model for a given value of price. We also highlight in red the average quantity obtained taking into account all the different models.

    As a last check (even if we have already taken preventive measures), we want to make sure that our model parameters do not share information. That is, we want to check that there is no collinearity between them.

    -

    To evaluate multicollinearity between the two parameters of our model, we plot the sampled values, one against the other. In the figure 4, we don’t see a pattern, they seem to be decorrelated, therefore multicollinearity is not present in our model, so we are good to go and we can continue with the problem.

    +

    To evaluate multicollinearity between the two parameters of our model, we plot the sampled values, one against the other. In figure 4, we don’t see a pattern, they seem to be decorrelated, therefore multicollinearity is not present in our model, so we are good to go and we can continue with the problem.

    begin
     scatter(post_loga, post_c, legend=false)
     xlabel!("log a")
    @@ -531,7 +531,7 @@ 

    9.2.2.4 Making uncertainty our al

    9.3 Maximizing profit

    Now that we have estimated our posterior distributions, we will try to answer the following question: what is the price that will give us the maximum profit?

    This is why we calculated the relationship between the price and the quantity of our product. As we said before, depending on that relation, it was going to be possible to define an optimal price point. Now we only have to add one more part to the equation: the production costs.

    -

    Having this, we will be able to set up our profit function that will tell us, for each price we choose, how much money we would expect to earn. So let´s define it:

    +

    Having this, we will be able to set up our profit function that will tell us, for each price we choose, how much money we would expect to earn. So let’s define it:

    As many of you know, the profit on the sale of a product is calculated as income minus costs.

    \(Profit=Price * Quantity - Cost\)

    But also the cost can be divided between the one that doesn’t depend on the production and I always have, and the one that does.

    @@ -547,12 +547,12 @@

    9.3 Maximizing profit

    Now we can plot the profit for many sampled values from the posterior distributions of our model and find the maximum.

    mxval, mxindx = findmax(mean(profit, dims=2); dims=1);
    mxval[1]
    -
    ## 579697.8940202671
    +
    ## 580629.7407600599

    With the unfavorable (or favorable) case of:

    unfav = mxval[1] - std(profit[mxindx[1][1], : ])
    -
    ## 548417.8658175807
    +
    ## 551273.5077073544
    fav = mxval[1] + std(profit[mxindx[1][1], : ])
    -
    ## 610977.9222229534
    +
    ## 609985.9738127654
    begin
     s = latexstring("\\mu_{Profit}")
     s2 = latexstring("\\mu_{Profit} \\pm \\sigma_{Profit}")
    @@ -575,7 +575,7 @@ 

    9.3 Maximizing profit

    In this way, not only do we have the information about the average profit (marked in red), but we also have a notion of the uncertainty that the model handles. As you can see in the graph and remembering that the highest price value we had in the pilot test was $5000, the uncertainty increases a lot for higher values, reflecting the lack of data.

    Then, analyzing the graph:

    The red line plotted is the mean expected profit and its maximum is near $4840. The region between the orange lines is approximately one standard deviation far from the expected value or where the 65% of the lines, plotted from the sampled values of our parameters, fall.

    -

    With this in mind and seeing that the profit curve is quite flat in the sector where the maximum is found, one could argue that it is preferable to choose a lower price since since the money lost would be minimal, but the volatility would go down considerably.

    +

    With this in mind and seeing that the profit curve is quite flat in the sector where the maximum is found, one could argue that it is preferable to choose a lower price since the money lost would be minimal, but the volatility would go down considerably.

    In order to see this, it would be interesting to graph the standard deviation of the profit according to the price we choose:

    std_p = [std(profit[i, : ]) for i in collect(1:length(p))];
    plot(p,std_p, legend=false, xlabel = "Price", ylabel= "Std deviation of profit", lw=2)
    @@ -589,12 +589,12 @@

    9.3 Maximizing profit

    #A faster way:
     prof_4000 = profit[findfirst(isequal(4000), p), :];
    mean_prof_4000 = mean(profit_4000)
    -
    ## 578540.069393245
    +
    ## 579251.5221961857

    With the unfavorable (or favorable) case of:

    unfav_4000 = mean(profit_4000) - std(profit_4000)
    -
    ## 551381.9489297445
    +
    ## 554168.5339511412
    mean(profit_4000) + std(profit_4000)
    -
    ## 605698.1898567455
    +
    ## 604334.5104412301
    begin   
     plot(p,mean(profit, dims=2) + std(profit, dims=2),  color = "orange", lw=2, label =s2)
     plot!(p,mean(profit, dims=2), color = "red", lw=4, label="")
    @@ -612,19 +612,19 @@ 

    9.3 Maximizing profit

    Then, by choosing a price of $4000 the average profit goes from $582800 to $58120. That is, a percentage variation of:

    porcentual_profit_diff = ((mean(profit_4000) - mxval[1]) / mxval[1]) * 100
    -
    ## -0.19972896899665932
    +
    ## -0.23736616764930557

    While the most unfavorable case goes from $549705 to $553298.5. That is, a percentage variation of:

    porcentual_std_diff = ( unfav_4000 - unfav) / unfav *100
    -
    ## 0.5404789480636205
    +
    ## 0.52515243401169
     porcentual_std_diff / porcentual_profit_diff
    -
    ## -2.7060618736416777
    +
    ## -2.212414849228099

    So, for every dollar we “lost” in average profitability, we gained more than double in the reduction of uncertainty.

    -

    Regardless of each person decision, the important thing about the Bayesian framework is that it allows us to include uncertainty in our models and use it to our advantage to make more informed and intelligent decisions.

    +

    Regardless of each person’s decision, the important thing about the Bayesian framework is that it allows us to include uncertainty in our models and use it to our advantage to make more informed and intelligent decisions.

    Instead of wanting to forget and get rid of uncertainty, Bayesianism allows us to accept that this is an inherent feature of reality and to take advantage of it. Being able to narrow down how sure we are about the inferences we make gives us an invaluable advantage when making decisions.

    9.4 Summary

    -

    In this chapter we have learned some basics concepts of economics such as the price elasticity of demand for a product, or the Pareto distribution of income and wealth. Then, we estimated the demand curve of a possible new product, performing a pilot test to see the relationship between price and quantity demanded. Thanks to Bayesian inference we were able to use the uncertainty we had to our advantage, quantifying the trade-off between expected return and the variability of it, making possible to perform a well informed decision.

    +

    In this chapter we have learned some basic concepts of economics such as the price elasticity of demand for a product, or the Pareto distribution of income and wealth. Then, we estimated the demand curve of a possible new product, performing a pilot test to see the relationship between price and quantity demanded. Thanks to Bayesian inference we were able to use the uncertainty we had to our advantage, quantifying the trade-off between expected return and the variability of it, making possible to perform a well informed decision.

    9.5 References