0% found this document useful (0 votes)
6 views7 pages

5th Answer Marios

This document details the estimation of a demand function using linear regression analysis, highlighting the relationship between price and demand. The analysis shows that price negatively affects demand, with a high R-squared value indicating a good model fit. Residual diagnostics confirm the model's assumptions, suggesting that further improvements could include testing nonlinear models and incorporating external factors.

Uploaded by

naresh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views7 pages

5th Answer Marios

This document details the estimation of a demand function using linear regression analysis, highlighting the relationship between price and demand. The analysis shows that price negatively affects demand, with a high R-squared value indicating a good model fit. Residual diagnostics confirm the model's assumptions, suggesting that further improvements could include testing nonlinear models and incorporating external factors.

Uploaded by

naresh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Demand Function Estimation Using Linear Regression

Marios Natsios

2025-03-13

Question
5. Now, please save the data points of the demand curve (price and demand) from question 4
in a new file and estimate a demand function using linear regression analysis. How well does
our regression model perform overall?

Introduction
Understanding how price affects demand is crucial in pricing strategy. In this analysis, we estimate a
demand function using linear regression. We use the demand curve data from Question 4, perform
regression modeling, and evaluate the model’s performance using various diagnostic tools.
A well-fitted regression model provides insights into price elasticity and helps determine the optimal pricing
strategy.

Data Preparation and Regression Analysis

library(readr)
library(ggplot2)
library(dplyr)
library(tidyr)
library(broom)
library(ggpubr)

# Load the demand curve data


file_path <- "C:/Users/nares/OneDrive/Documents/Demand_Curve_WTP.csv"
demand_data <- read_csv(file_path)

# Display first few rows


print(head(demand_data))

## # A tibble: 5 x 2
## Price Mean_Willingness
## <dbl> <dbl>

1
## 1 5 0.983
## 2 10 0.858
## 3 15 0.375
## 4 20 0.0917
## 5 25 0.0167

Summary of Data

• The dataset contains Price (Euro) and Mean Willingness to Buy.


• This data helps us analyze the relationship between price and demand.

Linear Regression Model

# Perform linear regression


demand_model <- lm(Mean_Willingness ~ Price, data = demand_data)

# Display regression summary


summary(demand_model)

##
## Call:
## lm(formula = Mean_Willingness ~ Price, data = demand_data)
##
## Residuals:
## 1 2 3 4 5
## -0.02167 0.12333 -0.09000 -0.10333 0.09167
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1.27500 0.12536 10.171 0.00203 **
## Price -0.05400 0.00756 -7.143 0.00565 **
## ---
## Signif. codes: 0 ’***’ 0.001 ’**’ 0.01 ’*’ 0.05 ’.’ 0.1 ’ ’ 1
##
## Residual standard error: 0.1195 on 3 degrees of freedom
## Multiple R-squared: 0.9445, Adjusted R-squared: 0.926
## F-statistic: 51.03 on 1 and 3 DF, p-value: 0.005649

Interpretation of Regression Model

• The coefficient for Price indicates how demand changes as price increases.
• The R-squared value shows how well the model explains demand variations.
• The p-value tests the significance of the regression coefficients.

2
Model Diagnostics and Evaluation

Actual vs. Predicted Demand Curve

demand_data$Predicted_Willingness <- predict(demand_model, newdata = demand_data)

ggplot(demand_data, aes(x = Price)) +


geom_point(aes(y = Mean_Willingness), color = "red", size = 3) +
geom_line(aes(y = Predicted_Willingness), color = "blue", size = 1) +
labs(title = "Actual vs. Predicted Demand Curve",
x = "Price (Euro)",
y = "Percentage Willing to Buy") +
theme_minimal()

## Warning: Using ‘size‘ aesthetic for lines was deprecated in ggplot2 3.4.0.
## i Please use ‘linewidth‘ instead.
## This warning is displayed once every 8 hours.
## Call ‘lifecycle::last_lifecycle_warnings()‘ to see where this warning was
## generated.

Actual vs. Predicted Demand Curve


1.00

0.75
Percentage Willing to Buy

0.50

0.25

0.00

5 10 15 20 25
Price (Euro)
### Summary - The red points represent actual demand, while the blue line shows predicted demand.
- A good fit is observed when predictions closely follow actual values.

3
Residual Plot

# Compute residuals
demand_data$Residuals <- demand_data$Mean_Willingness - demand_data$Predicted_Willingness

ggplot(demand_data, aes(x = Price, y = Residuals)) +


geom_point(color = "purple") +
geom_hline(yintercept = 0, linetype = "dashed", color = "black") +
labs(title = "Residual Plot",
x = "Price (Euro)",
y = "Residuals") +
theme_minimal()

Residual Plot

0.10

0.05
Residuals

0.00

−0.05

−0.10

5 10 15 20 25
Price (Euro)
### Summary - A random spread of residuals suggests a good model fit. - Patterns in residuals may
indicate missing nonlinear relationships.

Scatter Plot with Regression Line

ggplot(demand_data, aes(x = Price, y = Mean_Willingness)) +


geom_point(color = "red") +
geom_smooth(method = "lm", color = "blue", se = FALSE) +

4
labs(title = "Scatter Plot with Regression Line",
x = "Price (Euro)",
y = "Percentage Willing to Buy") +
theme_minimal()

## ‘geom_smooth()‘ using formula = ’y ~ x’

Scatter Plot with Regression Line


1.00

0.75
Percentage Willing to Buy

0.50

0.25

0.00

5 10 15 20 25
Price (Euro)
### Summary - The regression line shows a downward trend, indicating a negative relationship
between price and demand. - The slope represents price elasticity.

Histogram of Residuals

ggplot(demand_data, aes(x = Residuals)) +


geom_histogram(binwidth = 0.05, fill = "orange", color = "black", alpha = 0.7) +
labs(title = "Histogram of Residuals",
x = "Residuals",
y = "Frequency") +
theme_minimal()

5
Histogram of Residuals
2.0

1.5
Frequency

1.0

0.5

0.0

−0.10 −0.05 0.00 0.05 0.10


Residuals
### Summary - Normally distributed residuals confirm that linear regression is appropriate. -
Skewed residuals suggest the need for transformation.

Q-Q Plot of Residuals

ggqqplot(demand_data$Residuals, title = "Q-Q Plot of Residuals")

6
Q−Q Plot of Residuals

0.2
Sample

0.0

−0.2

−1.0 −0.5 0.0 0.5 1.0


Theoretical
### Summary - Residuals following the diagonal line indicate normality. - Deviations suggest
possible outliers or heteroscedasticity.

Conclusion
This analysis estimates a demand function using linear regression. The model allows us to understand
how demand changes with price variations.

Key Takeaways:

1. Price negatively affects demand, as shown by the negative coefficient in regression.


2. R-squared value indicates how well the model explains demand variation.
3. Residual diagnostics confirm model assumptions, with minimal violations.
4. Predicted demand aligns well with actual demand, validating the model’s usefulness.

Further improvements could include: - Testing nonlinear models to capture demand shifts. - Adding
external factors like competition or seasonal trends.

You might also like