Data Analysis: Fitting Distributions & Regression
Data Analysis: Fitting Distributions & Regression
Based on Clemen & Reilly, Making Hard Decisions with Decision Tools, Duxbury Press, 2004.
1
Agenda
Based on Clemen & Reilly, Making Hard Decisions with Decision Tools, Duxbury Press, 2004.
2
Objectives
Discrete probability
Create Histograms
Continuous probability
Construct CDFs (cumulative density functions)
1. Rank order the data (sort n data points from smallest to largest)
y1 < y2 < … < yn
2. Calculate centers of adjacent data points xm =(ym + ym+1)/2
3. Assign probability to each center (xm) such that P(X<=xm)=m/n
3
Example: Construct CDFs
y x
rental mid cumulative
rank costs points probability P(X<=64)=1/35
1 52 64.0 0.029
2 76 88.0 0.057
P(X<=88)=2/35
3 100 118.0 0.086 18 325 335.0 0.514
4 136 136.5 0.114 19 345 359.0 0.543
5 137 161.5 0.143 20 373 378.5 0.571
6 186 191.0 0.171 21 384 392.0 0.600
7 196 200.5 0.200 22 400 401.0 0.629
8 205 227.5 0.229 23 402 405.0 0.657
9 250 253.5 0.257 24 408 412.5 0.686
10 257 260.5 0.286
25 417 419.5 0.714
11 264 272.0 0.314
26 422 447.0 0.743
12 280 281.0 0.343
27 472 476.0 0.771
13 282 282.5 0.371
28 480 561.5 0.800
14 283 293.0 0.400
29 643 668.0 0.829
15 303 308.0 0.429
16 313 315.0 0.457 30 693 712.5 0.857
17 317 321.0 0.486 31 732 740.5 0.886
32 749 749.5 0.914
33 750 770.5 0.943
34 791 841.0 0.971
n=35 35 891 1
0.750
0.500
0.250
0.000
0 200 400 600 800
Yearly Bed Rental Cost
4
Fitting a Theoretical Probability Distribution
Goodness of Fit
5
Chi-Square Goodness-of-fit Test
Can be used for Discrete and Continuous Distributions
It is applied to binned data (i.e., data put into K bins or classes).
The test is dependent on how the data is binned (e.g. use equiprobable bins,
some software use 0.3s rule where s is the standard deviation)
Requires sufficient data in order for the chi-square approximation to be valid
(have at least 5 data points per bin, combine bins if data is not sufficient)
Test Statistic:
K K: number of bins
2 ( N i Ei ) 2 / Ei Ni: observed number of data points in bin i
i 1 Ei: expected number of data points in bin i
2 2 ,K c
c: estimated number of parameters
α: significance level for the test
2018 © Dr. Ozelkan Slide 11 Using Data
6
Anderson-Darling Goodness-of-fit Test
Can be used for Continuous Distributions
It is proven that the test
Captures deviations in spreads
Test Statistic:
A2 n S
where
2i 1
ln F (Yi ) ln[1 F (Yn1i )]
n
S
i 1 n
n: number of data points (or sample size)
Yi: ordered data
F(Yi): cumulative probability based on theoretical distribution and data point Yi
7
Step 1. Select Possible Distributions
8
Step 2. Estimate Parameters
f E (T t | m) me mt n
mˆ x xi / n 380.4
1 i 1
E (T )
m
1
Var (T )
m2
Normal
Distribution
0.8
0.6
0.0
0.0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1.0
Values in Thousands
9
Step 3. Compute Goodness of Fit
Expon(328.40) Shift=+42.617
1.0
0.8
Exponential
Distribution
0.6
0.0
0.0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
0.8
0.8
0.6
Normal: 0.6
Exponential:
BestFit Student Version BestFit Student Version
For Academic Use Only For Academic Use Only
0.0 0.0
0.0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1.0
0.0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1.0
10
Lab Exercise
11
Objectives
Why Regression?
12
Linear Regression
a
x (e.g. % young
where
population)
y = predicted (dependent) variable
x = predictor (independent) variable
b = slope of the line
a = value of y when x = 0 (the height of line at the y intercept)
Computing a and b
y
b
o e4 y=a+bx
e5
o
o e2
e3
o
e1
o
a
x
13
Computing a and b
y
(x4,y4) b
o y=a+bx
(x2,y2)
o
o
(x5,y5)
n=number of data points
o (x3,y3) (xt,yt) : observations
o
a (x1,y1)
x
n n n n n
n xt yt x t yt yt x t
t 1 t 1 t 1
b 2
a t 1
b t 1
n
n n n
n xt xt
2
t 1 t 1
2018 © Dr. Ozelkan Slide 28 Using Data
Example:
(1) (2) (1)^2 (1) x (2)
No. % Young Population Sales of Mountain Bikes Prediction
1 30 2400 900 72000 2235.135
2 15 1500 225 22500 1408.108
3 35 2200 1225 77000 2510.811
4 25 1800 625 45000 1959.459
5 40 3000 1600 120000 2786.486
total 145 10900 4575 336500 8575.676
3500
3000
b = (5 · 336500 - 145 · 10900) /
Sales of Mountain Bikes
2500
(5 · 4575-1452) = 55
2000
500
0
15 20 25 30 35 40 45 50
y= 581+55x
% Young People
14
Example – Multiple Regression
A market researcher for Super
Dollar Super Markets is
studying the yearly amount
families of four or more spend
on food. Three independent
variables are thought to be
related to yearly food
expenditures (Food). Those
variables are: total family
income (Income) in $00, size of
family (Size), and whether the
family has children in college
(College).
2018 © Dr. Ozelkan
Using Data
15
Example – Multiple Regression
Fam ily Food Incom e Size Student
1 3900 376 4 0
2 5300 515 5 1
3 4300 516 4 0
4 4900 468 5 0
5 6400 538 6 1
6 7300 626 7 1
7 4900 543 5 0
8 5300 437 4 0
9 6100 608 5 1
10 6400 513 6 1
11 7400 493 6 1
12 5800 563 5 0
2018 © Dr. Ozelkan
Using Data
Food
Expenditure=$954+$1.09*income+$748*size+$565*college
16
Example – Multiple Regression
Food
Expenditure=$954+$1.09*income+$748*size+$565*college
Each additional $100 dollars of income per year will
increase the amount spent on food by $109 per year.
An additional family member will increase the amount
spent per year on food by $748.
A family with a college student will spend $565 more per
year on food than those without a college student.
Food Expenditure=$954+$1.09*500+$748*4+$565*0
So a family of 4, with no college students, and an income
of $50,000 will spend an estimated $4,491.
2018 © Dr. Ozelkan
Using Data
y 0 1 x1 2 x2 3 x3
Given data for n=15 observations, how would we estimate
the parameters?
Output: y Input 1: x1 Input 2: x2 Input 3: x3
Advertising Competition
Promotion Sales ($1000s) ($1000s) Price ($) Price ($)
1 10541 366 90.99 96.95
2 8891 377 90.99 93.99
3 5905 387 94.99 90.99
4 8251 418 96.99 97.95
5 11461 434 92.99 97.95
?
0 , 1 , 2 , 3
6 6924 450 95.95 93.95
7 7347 457 93.95 90.99
8 10972 466 91.95 96.95
9 7811 467 96.95 94.99
10 10559 468 92.95 96.95
11 9825 468 97.99 98.95
12 9130 475 91.95 90.99
13 5116 479 99.95 91.95
14 7830 479 96.99 95.95
15 8388 481 91.95 90.95
17
Multivariate Linear Regression
y 0 1 x1 2 x2 ... k xk
Given data for n observations, how would we estimate the
parameters? (out:output, in: input)
data out in1 in2 ... ink
1 y1 x11 x21 ... xk1
?
2 y2 x12 x22 ... xk2 0 , 1 , 2 ,..., k
... ...
n yn x1n x2n ... xkn
2018 © Dr. Ozelkan Slide 36 Using Data
Multivariate Regression
Note that for each data you can write an equation in which
the parameters are unknowns
18
Multivariate Regression
( X T X ) 1 X T y
19
Remarks
Note that the simple linear regression analysis is a specific case of the
multivariate linear regression case
thus the parameter estimation for a simple linear regression using the
parameter estimation formula for the multivariate linear regression would
result in the same estimates as the simple linear regression expressions
described earlier.
Main assumption of a regression is that the errors are random
In fact a check on this assumption is necessary for a valid regression
analysis.
To make statistical testing we also assume that errors are normally
distributed with a mean μ=0 and standard deviation of σ
You also assume that the input variables have significant impact on the
output variable
Again this assumption needs to be checked as well.
Regression Outputs
0 , 1 , 2 ,..., k
Correlation between the actual outputs and predicted outputs (as
given by regression)
Statistical significance of the parameters
Statistical significance of the regression
Would provide graphs for the
Regression prediction errors (also called residuals)
Line fit between the actual outputs and predicted outputs
Normal probability plot which indicates if the errors are random and
normally distributed.
20
Statistical Tests for Regression
H 0 : 0 1 2 ... k 0
H 1 : j 0, for at least one j
Rejection of H0 (Null hypothesis) implies at least one input
variable is significant to define this regression model.
To test this regression an F-test is conducted
MS R SSR / k where SSR indicates
F0 the sum of squares
MS E SSE /(n k 1) regression and SSE
the sum of squares
H0 is rejected if F0 > Fα,k,n-k-1 error. SEE NEXT
PAGE FOR MORE
2018 © Dr. Ozelkan Slide 43 DETAILS
Using Data
21
Remark on the Test for Significance of
Overall Regression
The test presented on the previous page assumes that the total variation
in the data behavior will be partially explained by the regression model
and partially by the random error. In other words:
Computing Expressions
n
SS Total ( SST ) ( yi y ) 2 SS Regression SS Error
i 1
Average of all
n outputs
SS Regression ( SS R ) ( yˆ i y ) 2 Individual
i 1 observations
n n
SS Error ( SS E ) ( yi yˆ i ) 2 ei
2
Regression
prediction for
i 1 i 1 each individual
SS T SS R SS E observation
SS R SST SS E
22
Computing Expressions (cont.)
SS R SS
R2 1 E
SST SST
2 2 SS E (n k 1)
Radjusted Ra 1
SST (n 1)
2
Ra R 2
standard error of ˆ j
diagonal element of
ˆ C jj
2
(XTX)-1
H0 is rejected if |t0| > tα/2, n-k-1
23
Reading the Regression Output
SUMMARY OUTPUT
Adj. R-Square shows Confidence Level for
Regression Statistics correlation that is Significance of
Multiple R 0.896661 between 0 and 1. High is Regression = 1-
R Square 0.804002 Significance F, thus
good! Here it is
Adjusted R Square
0.730502
Standard Error
572.6871 0.730~73% very good! low “Significance F”
Observations 12 shows good
regression relation!
ANOVA Here =1-
df SS MS F Significance F
Regression 3 10762903 3587634 10.93889 0.003334
0.003334=0.9967~99.
Residual 8 2623764 327970.5 67% indicates very
Total 11 13386667 good regression
relation!
Coefficients
Standard Error t Stat P-value Lower 95%Upper 95%
Intercept 954.0238 1580.839 0.603492 0.562897 -2691.4 4599.445
Income 1.0918 3.153489 0.34622 0.738107 -6.18016 8.36376
Size 748.3837 302.9535 2.470293 0.038693 49.77177 1446.996
Student 564.5213 495.1349 1.140136 0.287212 -577.262 1706.304
Using Minitab
Regression Analysis: Sales versus Population
Running
Predictor Coef SE Coef T P
Constant 581.1 409.3 1.42 0.251
Population 55.14 13.53 4.07 0.027
Regression in
S = 260.284 R-Sq = 84.7% R-Sq(adj) = 79.6%
Minitab:
Stat=>regression
PRESS = 602182 R-Sq(pred) = 54.65%
Analysis of Variance
=> regression
Source DF SS MS F P
Regression 1 1124757 1124757 16.60 0.027
Residual Error 3 203243 67748
Total 4 1328000
24
Lab Exercise
25