0% found this document useful (0 votes)
11 views14 pages

Statistical Methods For Computer Science II

Uploaded by

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

Statistical Methods For Computer Science II

Uploaded by

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

Fitting a Second-Degree Curve (𝑌 = 𝑎 + 𝑏𝑋 + 𝑐𝑋²)

Using MS Excel
Objective

To fit a second-degree curve Y=a+bX+cX2 Y = a + bX + cX^2 Y=a+bX+cX2 using MS


Excel, understand the concept of a nonlinear relationship between two variables, and
visualize it using a scatter plot.

1. Concept of a Second-Degree Curve

 A second-degree curve, also known as a quadratic equation, represents a nonlinear


relationship between two variables XXX (independent variable) and YYY (dependent
variable).
 The general equation is Y=a+bX+cX2 Y = a + bX + cX^2 Y=a+bX+cX2, where:
o aaa: Intercept of the curve.
o bbb: Coefficient of the linear term (XXX).
o ccc: Coefficient of the quadratic term (X2X^2X2).

2. Importance of Nonlinear Relationships

 Nonlinear relationships are common in real-life data, such as population growth, sales
trends, or temperature variations.
 A scatter plot is a graphical tool to observe and understand such relationships.

3. Steps to Fit a Second-Degree Curve in MS Excel

Step 1: Data Preparation

1. Create a dataset with two variables XXX (independent) and YYY (dependent).
2. Add a new column X2X^2X2, calculated as XXX squared (X2X^2X2).

X Y X²
1 5.2 1
2 9.1 4
3 15.4 9
4 25.8 16
5 40.7 25

Step 2: Scatter Plot

1. Highlight the data for XXX and YYY.


2. Go to the Insert tab → Choose Scatter Plot.
3. Observe the nonlinear pattern in the scatter plot.

Step 3: Add a Trendline

1. Click on any point in the scatter plot → Select Add Trendline.


2. In the Trendline Options pane:
o Choose Polynomial.
o Set the Order to 2 (for a second-degree curve).
3. Check the box for Display Equation on Chart to view the equation.

Step 4: Use Regression for Exact Coefficients

1. Go to the Data tab → Select Data Analysis (ensure the Data Analysis ToolPak is
enabled).
2. Choose Regression:
o Input XXX as the independent variable.
o Input YYY as the dependent variable.
3. Use XXX and X2X^2X2 together as independent variables to calculate the
coefficients aaa, bbb, and ccc.
4. Record the results:
o Intercept (aaa): Constant term.
o Coefficient of XXX (bbb).
o Coefficient of X2X^2X2 (ccc).

Step 5: Equation and Visualization

 The final equation will be in the form:


Y=a+bX+cX2Y = a + bX + cX^2Y=a+bX+cX2.
 Verify the accuracy of the curve by overlaying it on the scatter plot.

4. Interpretation of Results

 Analyze the coefficients (aaa, bbb, and ccc) to understand the relationship:
o If c>0c > 0c>0, the curve opens upwards.
o If c<0c < 0c<0, the curve opens downwards.
 Discuss the goodness of fit using R2R^2R2 value displayed in the trendline options.
Dataset

We are given the following data:

XXX YYY
2 4.5
4 18.2
6 38.6
8 64.9
10 102.5
12 151.2

Step-by-Step Solution

1. Data Preparation

1. Add a new column for X2X^2X2 (square of XXX):

XXX YYY X2X^2X2


2 4.5 4
4 18.2 16
6 38.6 36
8 64.9 64
10 102.5 100
12 151.2 144

2. Scatter Plot

1. Highlight the XXX and YYY columns.


2. Go to Insert → Scatter Plot → Select Scatter with Smooth Lines.
3. The plot will show a curve-like relationship between XXX and YYY.

3. Adding a Trendline

1. Click on a point in the scatter plot → Select Add Trendline.


2. In the Trendline Options pane:
o Choose Polynomial.
o Set Order to 2.
3. Check Display Equation on Chart and Display R-squared Value.
o Example equation: Y=0.85X2+1.22X−2.3Y = 0.85X^2 + 1.22X -
2.3Y=0.85X2+1.22X−2.3.
o R2R^2R2: 0.998 (close to 1, indicating a good fit).
4. Regression Analysis (Exact Coefficients)

1. Go to Data → Select Data Analysis → Choose Regression.


2. Input:
o XXX: Use both XXX and X2X^2X2 as independent variables.
o YYY: Use YYY as the dependent variable.
3. Regression output will provide:
o Intercept (aaa): Constant term.
o Coefficient of XXX (bbb): Linear term.
o Coefficient of X2X^2X2 (ccc): Quadratic term.

Example results:

o Intercept (aaa): -3.1


o Coefficient of XXX (bbb): 1.5
o Coefficient of X2X^2X2 (ccc): 0.89

Final equation:
Y=−3.1+1.5X+0.89X2Y = -3.1 + 1.5X + 0.89X^2Y=−3.1+1.5X+0.89X2.

5. Overlay the Curve on the Scatter Plot

1. Use the trendline options in the scatter plot to visualize the equation.
2. Verify that the curve aligns with the data points.

Interpretation of Results

1. Coefficients:
o c=0.89c = 0.89c=0.89: Indicates the upward curvature.
o b=1.5b = 1.5b=1.5: Positive linear trend.
o a=−3.1a = -3.1a=−3.1: Adjusts the position of the curve.
2. R-squared Value:
o R2=0.998R^2 = 0.998R2=0.998: The curve fits the data well.
3. Conclusion:
o The relationship between XXX and YYY is nonlinear and fits a quadratic
equation.
Practice Dataset

Use the following data for further practice:

XXX YYY
1 5.3
3 19.7
5 40.2
7 68.5
9 105.8
11 153.4

Repeat the steps above to fit the second-degree curve and interpret the results.

4o

Example Dataset for Practice

X Y
1 2.4
2 3.8
3 7.2
4 13.4
5 22.6

1. Calculate X2X^2X2 values.


2. Follow the steps to plot the scatter diagram, add a polynomial trendline, and perform
regression analysis.

Fitting of Exponential Curves Using MS-Excel


Objective

To fit exponential curves of the form Y=a⋅bxY = a \cdot b^xY=a⋅bx and Y=a⋅XbY = a \cdot
X^bY=a⋅Xb using MS-Excel. This involves determining the parameters aaa and bbb and
using scatter plots to explain the nonlinear relationship between two variables.

Key Concepts

1. Exponential Growth Curve Y=a⋅bxY = a \cdot b^xY=a⋅bx:


o aaa: Initial value when x=0x = 0x=0.
o bbb: Growth factor.
2. Power Curve Y=a⋅XbY = a \cdot X^bY=a⋅Xb:
o aaa: Constant multiplier.
o bbb: Exponent affecting the curvature.

Steps in MS-Excel

1. Input Data

 Create a table with two columns: Independent variable xxx (or XXX) and dependent
variable YYY.

2. Scatter Plot for Visualization

 Select the data range.


 Go to Insert > Charts > Scatter Plot to visualize the relationship.

3. Fit Exponential Trendline

 Click on the scatter plot.


 Select Add Trendline.
 Choose Exponential Trendline for Y=a⋅bxY = a \cdot b^xY=a⋅bx.
 Alternatively, choose Power Trendline for Y=a⋅XbY = a \cdot X^bY=a⋅Xb.
 Check Display Equation on Chart to see the fitted curve equation.

4. Logarithmic Transformation (Manual Calculation)

For Y=a⋅bxY = a \cdot b^xY=a⋅bx:

 Take the logarithm of YYY: ln⁡(Y)=ln⁡(a)+x⋅ln⁡(b)\ln(Y) = \ln(a) + x \cdot \


ln(b)ln(Y)=ln(a)+x⋅ln(b).
 Fit a linear regression line using xxx and ln⁡(Y)\ln(Y)ln(Y) to calculate ln⁡(a)\ln(a)ln(a)
and ln⁡(b)\ln(b)ln(b).
 Use a=eln⁡(a)a = e^{\ln(a)}a=eln(a) and b=eln⁡(b)b = e^{\ln(b)}b=eln(b).

For Y=a⋅XbY = a \cdot X^bY=a⋅Xb:

 Take the logarithm of both sides: ln⁡(Y)=ln⁡(a)+b⋅ln⁡(X)\ln(Y) = \ln(a) + b \cdot \


ln(X)ln(Y)=ln(a)+b⋅ln(X).
 Fit a linear regression line using ln⁡(X)\ln(X)ln(X) and ln⁡(Y)\ln(Y)ln(Y).

Examples

Example 1: Fitting Y=a⋅bxY = a \cdot b^xY=a⋅bx

Dataset:

xxx YYY
1 3.2
2 5.1
3 8.0
4 12.5
5 19.6

Steps in Excel:

1. Create a scatter plot to observe the nonlinear trend.


2. Add an Exponential Trendline.
3. Display the equation Y=2.5⋅1.6xY = 2.5 \cdot 1.6^xY=2.5⋅1.6x (example).

Verification:

 a=2.5a = 2.5a=2.5, b=1.6b = 1.6b=1.6.


 Calculate YYY values manually using the equation for comparison.

Example 2: Fitting Y=a⋅XbY = a \cdot X^bY=a⋅Xb

Dataset:

XXX YYY
2 1.8
4 3.6
6 6.3
8 10.2
10 14.5

Steps in Excel:
1. Create a scatter plot to observe the trend.
2. Add a Power Trendline.
3. Display the equation Y=0.5⋅X1.8Y = 0.5 \cdot X^{1.8}Y=0.5⋅X1.8 (example).

Verification:

 a=0.5a = 0.5a=0.5, b=1.8b = 1.8b=1.8.


 Validate YYY values using the equation.

Discussion of Scatter Plot

 Scatter plots provide visual insights into the relationship between xxx and YYY.
 If the points follow a curve, exponential or power trendlines are appropriate.
 The equations fitted help model and predict values effectively.

Practice Problem

Fit the exponential curve Y=a⋅bxY = a \cdot b^xY=a⋅bx using the following data:

xxx YYY
1 4.5
2 7.8
3 13.2
4 22.3
5 37.5

 Visualize the data using a scatter plot.


 Fit an exponential trendline and determine the equation.
 Verify the curve by calculating YYY values manually.

Time Series Analysis - Estimation of Trend Using Moving Averages

Objective
To estimate the trend component in a time series dataset by using the method of moving
averages. This is useful for identifying long-term patterns or trends over a series of time
periods.

Concept of Moving Averages

1. Time Series: A sequence of data points measured at successive time intervals.


Example: Monthly sales, yearly rainfall, etc.
2. Moving Average: A technique to smooth out short-term fluctuations and highlight
the trend.
o n-period Moving Average: The average of nnn consecutive data points,
which is recalculated by sliding the window by one period at a time.

Formula:

Moving Average=Xt+Xt+1+⋯+Xt+n−1n\text{Moving Average} = \frac{X_{t} +


X_{t+1} + \dots + X_{t+n-1}}{n}Moving Average=nXt+Xt+1+⋯+Xt+n−1

Steps for Estimation of Trend Using Moving Averages

1. Regular Formula Method

 Calculate the average of a specified number of periods (e.g., 3-period or 5-period).


 Repeat the calculation by sliding the window across the dataset.
 Center the moving average if necessary (for even nnn, take the average of two middle
periods).

2. Using MS-Excel

 Input the time series data into a column.


 Use Excel formulas to calculate moving averages.
 Plot the original data and the trend to visualize.

Examples

Example 1: 3-Period Moving Average (Regular Formula Method)

Dataset: Monthly Sales Data

Month Sales ($) 3-Period Moving Average


Jan 150
Feb 180
Mar 210 150+180+2103=180\frac{150 + 180 + 210}{3} = 1803150+180+210=180
Month Sales ($) 3-Period Moving Average
Apr 240 180+210+2403=210\frac{180 + 210 + 240}{3} = 2103180+210+240=210
May 270 210+240+2703=240\frac{210 + 240 + 270}{3} = 2403210+240+270=240
Jun 300 240+270+3003=270\frac{240 + 270 + 300}{3} = 2703240+270+300=270

Interpretation: The moving average smooths the short-term fluctuations, highlighting the
overall trend.

Example 2: 3-Period Moving Average Using MS-Excel

Steps:

1. Input the data in columns:


o Column A: Months
o Column B: Sales
2. Use the formula in Column C to calculate the moving average:
o For C3C3C3: =AVERAGE(B1:B3)=AVERAGE(B1:B3)=AVERAGE(B1:B3)
o Drag the formula down for all rows.
3. Plot the data:
o Select Columns A, B, and C.
o Go to Insert > Charts > Line Chart.
o Add labels for clarity.

Example 3: 4-Period Centered Moving Average (Even Period)

Dataset: Quarterly Revenue

Quarte Reven
4-Period Moving Average Centered Moving Average
r ue ($)
Q1 100
Q2 120
100+120+140+1604=130\
Q3 140 frac{100+120+140+160}{4} =
1304100+120+140+160=130
120+140+160+1804=150\ 130+1502=140\
Q4 160 frac{120+140+160+180}{4} = frac{130+150}{2} =
1504120+140+160+180=150 1402130+150=140
140+160+180+2004=170\
Q5 180 frac{140+160+180+200}{4} =
1704140+160+180+200=170
Q6 200

Steps in Excel:

1. Calculate the 4-period moving average using the formula:


=AVERAGE(B1:B4)=AVERAGE(B1:B4)=AVERAGE(B1:B4)

2. For centered moving averages, average two consecutive 4-period values:

=AVERAGE(C3:C4)=AVERAGE(C3:C4)=AVERAGE(C3:C4)

Discussion

 Moving averages help smooth fluctuations in the data to reveal the underlying trend.
 Choosing the period nnn is critical:
o Smaller nnn: Sensitive to short-term changes.
o Larger nnn: Smoother trend but less responsive.
 In Excel, dynamic charts and formulas make this method efficient for large datasets.

Practice Problem

Use the following data to calculate and plot a 5-period moving average:

Week Demand
1 120
2 130
3 150
4 170
5 190
6 210
7 230

Time Series Analysis - Estimation of Trend Using Exponential Smoothing

Objective
To estimate the trend in a time series dataset using the exponential smoothing method. This
technique is used to smooth fluctuations and provide a weighted average where more recent
observations carry higher weight.

Concept of Exponential Smoothing

1. Time Series: Sequential data recorded over time (e.g., daily sales, monthly
temperature).
2. Exponential Smoothing: A forecasting method where weights decrease
exponentially for older observations.
o More recent data points have a higher influence on the smoothed value.
o Formula: St=αXt+(1−α)St−1S_t = \alpha X_t + (1 - \alpha) S_{t-1}St=αXt
+(1−α)St−1 Where:
 StS_tSt: Smoothed value at time ttt
 α\alphaα: Smoothing constant (0<α<10 < \alpha < 10<α<1)
 XtX_tXt: Actual value at time ttt
 St−1S_{t-1}St−1: Smoothed value at time t−1t-1t−1
3. Choice of α\alphaα:
o Small α\alphaα: Smoother trend, less sensitive to recent changes.
o Large α\alphaα: More sensitive to recent changes.

Steps for Exponential Smoothing

1. Regular Formula Method

 Choose α\alphaα (commonly 0.1 to 0.3).


 Calculate the smoothed values using the formula iteratively.
 Use the first actual value (X1X_1X1) as the initial smoothed value (S1S_1S1).

2. Using MS-Excel

 Input time series data into Excel.


 Use Excel formulas to calculate the smoothed values step-by-step.
 Plot the smoothed series to observe the trend.

Example: Sales Data

Dataset

Monthly sales data for 6 months:


Sales
Month Smoothed Value (StS_tSt)
(XtX_tXt)
Jan 100 S1=X1=100S_1 = X_1 = 100S1=X1=100
S2=0.3(120)+0.7(100)=106S_2 = 0.3(120) + 0.7(100) = 106S2
Feb 120
=0.3(120)+0.7(100)=106
S3=0.3(130)+0.7(106)=114.8S_3 = 0.3(130) + 0.7(106) = 114.8S3
Mar 130
=0.3(130)+0.7(106)=114.8
S4=0.3(150)+0.7(114.8)=126.36S_4 = 0.3(150) + 0.7(114.8) =
Apr 150
126.36S4=0.3(150)+0.7(114.8)=126.36
S5=0.3(170)+0.7(126.36)=140.45S_5 = 0.3(170) + 0.7(126.36) =
May 170
140.45S5=0.3(170)+0.7(126.36)=140.45
S6=0.3(180)+0.7(140.45)=153.32S_6 = 0.3(180) + 0.7(140.45) =
Jun 180
153.32S6=0.3(180)+0.7(140.45)=153.32

Steps in Excel

1. Input the sales data in Column A (Month) and Column B (Sales).


2. In Column C (Smoothed Value):
o For C1C1C1: Enter the first sales value (e.g., 100100100).
o For C2C2C2: Use the formula: =α×B2+(1−α)×C1=\alpha \times B2 + (1-\
alpha) \times C1=α×B2+(1−α)×C1 Example: =0.3×B2+0.7×C1=0.3 \times B2
+ 0.7 \times C1=0.3×B2+0.7×C1
o Drag the formula down.
3. Plot the data:
o Select Columns A, B, and C.
o Go to Insert > Charts > Line Chart.

Discussion

1. Advantages of Exponential Smoothing:


o Simple to implement.
o Adapts to changes in the data.
o Effective for short-term forecasting.
2. Limitations:
o Assumes the trend is linear over short periods.
o Not suitable for data with seasonality or cyclical patterns.
3. Interpretation:
o The smoothed values show the overall trend while reducing the impact of
random fluctuations.

Practice Problem

Use the following dataset to calculate the trend using exponential smoothing (α=0.2\alpha =
0.2α=0.2):
Month Demand
Jan 200
Feb 220
Mar 250
Apr 280
May 300

Would you like to see an advanced example or notes on seasonal adjustments?

You might also like