This requires using python or excel. Manually is too much work.
WITH EXCEL:
We will use excel’ s functionality for creating scatter plots with logarithmic trendlines. Here’s how you can do it step-by-step. For excel, assume that your data is placed in columns A (Demand) and B (Price) starting from the second row. The first row is used for headers, "A1" is "Demand (D)" and "B1" is "Price of One Shirt(P)".
Step 1: Enter the Data
-
A1: Demand (D)
-
B1: Price of One Shirt(P)
-
A2 to A8: 152, 159, 164, 171, 176, 180, 189 (Enter these demands sequentially from A2 to A8)
-
B2 to B8: 2300, 2000, 1700, 1500, 1300, 1200, 1000 (Enter these prices sequentially from B2 to B8)
Step 2: Create a Scatter Plot
- Highlight the range A1:B8.
- Go to the "Insert" tab.
- In the Charts group, click on the "Scatter" chart type.
- Choose the "Scatter with only markers" chart type.
Step 3: Add a Logarithmic Trendline
- Click on one of the data points in your scatter plot. All points should become selected.
- Go to the "Chart Tools Design" tab.
- Click "Add Chart Element" > "Trendline" > "More Trendline Options".
- In the "Format Trendline" pane, select "Logarithmic".
- Check the "Display Equation on chart" and "Display R-squared value on chart" (if desired) to show the regression equation and R² value.
Step 4: Using the Equation
- Once you’ve added the logarithmic trendline and displayed the equation, you should see an equation on your chart something like: y = a⋅ln(x)+b
Now you can use this function to calculate estimated price values for different demand values. To apply this manually in Excel:
- Note down the a and b values from the chart.
- Use the formula in another cell. Suppose you want to find the estimated price for a demand of 165: Estimated Price=a⋅ln(165)+b
- Replace a and b with the noted values from the equation on the chart.
Example Formula Application:
Assume that the function from the trendline is: y = 500⋅ln(x)−1000
In a cell, you could write a formula like this to calculate the price for a demand of 165:
= 500 * LN(165) - 1000
Replace the coefficient and constant with those from your actual trendline equation. Remember that these steps provide a mathematical model to fit your data and predict future points, but it’s based on the assumption that future data will continue to follow the same trend. Always apply caution when making predictions with models!
WITH PYTHON:
import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit
# Given data
D = np.array([152, 159, 164, 171, 176, 180, 189])
P = np.array([2300, 2000, 1700, 1500, 1300, 1200, 1000])
# Define the form of the function you want to fit.
# a * np.log(b * D) can be a good starting point.
def func(D, a, b):
return a * np.log(b * D)
# Use curve_fit to fit the function to the data.
popt, pcov = curve_fit(func, D, P)
# Now, popt contains the optimized parameters (a and b).
a, b = popt
# Generate x values
D_fit = np.linspace(min(D), max(D), 100)
# Generate fitted y values
P_fit = func(D_fit, a, b)
# Plot the original data as scatter
plt.scatter(D, P, label='Original Data')
# Plot the fitted curve
plt.plot(D_fit, P_fit, 'r', label=f'Fitted Curve: {a:.2f} * log({b:.2f} * D)')
plt.xlabel('Demand (D)')
plt.ylabel('Price of One Shirt(P)')
plt.legend()
plt.title('Logarithmic Fit Example')
plt.show()
In the script above:
-
D and P are your original data points.
-
func(D, a, b) defines the logarithmic function to fit the data.
-
curve_fit(func, D, P) will try to find the best parameters a and b to fit your data.
- The fitted parameters a and b are then used to create a fitted curve which is plotted alongside your original data points.
The form of the function a * np.log(b * D) might need to be adjusted depending on the exact nature and behavior of your data.