Docsity

Topic Overview - Applied Regression Analysis | STAT 51200, Study notes of Statistics

Toggle sidebar
bg1
Topic01.doc 8/22/05 11:34 AM
1 of 24
Stat 512 Topic 1
PPT 1
Topic Overview
This topic we will cover:
− Course Overview & Policies
− SAS
− KNNL Chapter 1 (much should be review) – Simple linear regression
− KNNL Chapter 2 – Inference in simple linear regression, Prediction intervals and Confidence bands,
ANOVA tables, General Linear Test
Class website
http://web.ics.purdue.edu/~simonsen/stat512/
Class policies
Refer to handout.
Overview
We will cover
- simple linear regression (SLR) (Chapters 1 – 5)
- multiple regression (MLR) (Chapters 6 – 11)
- analysis of variance (ANOVA) (Chapters 16 – 25)
The emphasis will be placed on using selected practical tools using SAS rather than on the mathematical
manipulations. We want to understand the theory so that we can apply it appropriately. Some of the
material on SLR will be review, but our goal with SLR is to be able to generalize the methods to MLR.
References
− Text: Applied Linear Statistical Models, (4th ed.) by Neter, Kutner, Nachtsheim and Wasserman
(KNNL).
− SAS System for Regression by Freund and Little.
− SAS/STAT User’s Guide Vol. 1 and 2.
− SAS System for Elementary Analysis by Schlotzhauer.
− SAS Help menus
SAS
Getting Help with SAS
Statistical Consulting Service
Math B5
Hours 10-4 M through F
http://www.stat.purdue.edu/consulting/
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18

Partial preview of the text

Download Topic Overview - Applied Regression Analysis | STAT 51200 and more Study notes Statistics in PDF only on Docsity!

Stat 512 Topic 1

PPT 1

Topic Overview

This topic we will cover: − Course Overview & Policies − SAS − KNNL Chapter 1 (much should be review) – Simple linear regression − KNNL Chapter 2 – Inference in simple linear regression, Prediction intervals and Confidence bands, ANOVA tables, General Linear Test

Class website

http://web.ics.purdue.edu/~simonsen/stat512/

Class policies

Refer to handout.

Overview

We will cover

  • simple linear regression (SLR) (Chapters 1 – 5)
  • multiple regression (MLR) (Chapters 6 – 11)
  • analysis of variance (ANOVA) (Chapters 16 – 25) The emphasis will be placed on using selected practical tools using SAS rather than on the mathematical manipulations. We want to understand the theory so that we can apply it appropriately. Some of the material on SLR will be review, but our goal with SLR is to be able to generalize the methods to MLR.

References

− Text: Applied Linear Statistical Models, (4th^ ed.) by Neter, Kutner, Nachtsheim and Wasserman (KNNL). − SAS System for Regression by Freund and Little. − SAS/STAT User’s Guide Vol. 1 and 2.

− SAS System for Elementary Analysis by Schlotzhauer.

− SAS Help menus

SAS

Getting Help with SAS

Statistical Consulting Service

Math B Hours 10-4 M through F http://www.stat.purdue.edu/consulting/

Evening computer labs

− Room? − help with SAS, Excel for multiple Stat courses − Hours 7– 9 M through Th − starting second week of classes − staffed with graduate student TA’s

SAS

SAS is the program we will use to perform data analysis for this class. I will often give examples from SAS in class. The commands are meant to be all together as one program but it will be easier to understand if I show each command followed by its output. The programs will be available for you to download from the website.

I will use the following font convention in the lecture notes: SAS input will look like this: Courier New SAS output will look like this: SAS Monospace

I will usually have to edit the output somewhat to get it to fit on the page of notes. My own comments will be in regular (Times/printout or Arial/lecture) fonts like this. Let me know if you get confused about what is input, output, or my comments. You should run the SAS programs yourself to see the real output, and experiment with changing the commands to learn how they work. I will tell you the names of all SAS files I use in these notes. If the notes differ from the SAS file, take the SAS file to be correct, since there may be cut-and-paste errors.

There is a tutorial in SAS to help you get started. Help Æ Getting Started with SAS Software. You should spend some time before next week getting comfortable with SAS (see HW #0).

For today, don’t worry about the detailed syntax of the commands. Just try to get a sense of what is going on.

Example (Price Analysis for Diamond Rings in Singapore)

Variables

− response variable price in Singapore dollars (Y) − explanatory variable weight of diamond in carats (X)

Goals

− create a scatterplot of the data − fit a regression line − predict the price of a sale for a 0.43 carat diamond ring

SAS Data Step

− file diamond.sas on website

One way to input data in SAS is to just type or paste it in. In this case, we have a sequence of ordered pairs (weight, price).

run ;

Now we want to use simple linear regression to fit a line through the data. We use the symbol option “i=rl” meaning “interpolation = regression line” (that’s an L not a one).

symbol1 v=circle i=rl; title2 'Scatter plot of Price vs. Weight with Regression Line'; proc gplot data=diamonds1; plot price*weight / haxis=axis1 vaxis=axis2; run ;

SAS Proc Reg

We use proc reg (regression) to estimate a regression line and calculate predictors and residuals from the straight line. We tell it what the data are, what the model is, and what options we want.

proc reg data=diamonds; model price=weight/p r; output out=diag p=pred r=resid; id weight; run ; Analysis of Variance

Sum of Mean Source DF Squares Square F Value Pr > F Model 1 2098596 2098596 2069.99 <. Error 46 46636 1013. Corrected Total 47 2145232

Root MSE 31.84052 R-Square 0. Dependent Mean 500.08333 Adj R-Sq 0. Coeff Var 6. Parameter Estimates Parameter Standard Variable DF Estimate Error t Value Pr > |t| Intercept 1 -259.62591 17.31886 -14.99 <. weight 1 3721.02485 81.78588 45.50 <.

proc print data=diag; run ; Output Statistics

Dep Var Predicted Std Error Std Error Obs weight price Value Mean Predict Residual Residual

1 0.17 355.0000 372.9483 5.3786 -17.9483 31. 2 0.16 328.0000 335.7381 5.8454 -7.7381 31. 3 0.17 350.0000 372.9483 5.3786 -22.9483 31. 4 0.18 325.0000 410.1586 5.0028 -85.1586 31. 5 0.25 642.0000 670.6303 5.9307 -28.6303 31. ... 46 0.15 287.0000 298.5278 6.3833 -11.5278 31. 47 0.26 693.0000 707.8406 6.4787 -14.8406 31. 48 0.15 316.0000 298.5278 6.3833 17.4722 31. 49 0.43. 1340 19...

PPT 2

Simple Linear Regression

Why Use It?

− Descriptive purposes (cause/effect relationships) − Control (often of cost) − Prediction of outcomes

− b 0 is the estimated intercept

− b 1 is the estimated slope

− Y ˆ i is the estimated mean for Y when the predictor is X (^) i (i.e. the point on the fitted line)

− is the residual for the i th^ case (the vertical distance from the data point to the fitted regression

line). Note that

e i

e i = Yi − Y ˆ i = Yi − ( b 0 + b X 1 i )

Using SAS to plot the residuals (Diamond Example)

When we called PROC REG earlier, we assigned the residuals to the name “resid” and placed them in a new data set called “diag”. We now plot them vs. X.

symbol1 v=circle i=NONE; title2 color=blue 'Residual Plot'; axis2 label=(angle= 90 'Residual'); proc gplot data=diag; plot residweight / haxis=axis1 vaxis=axis2 vref= 0 ; where price ne.* ; run ;

Notice there does not appear to be any obvious pattern in the residuals. We’ll talk a lot more about diagnostics later, but for now you should know that looking at residual plots is an important way to check assumptions.

Least Squares

− want to find “best” estimates b 0 and b 1

− will minimize the sum of the squared residuals (^) ( ( )) 2 2 0 1 1 1

n n i i i i i

e Y b b X = =

∑ =^ ∑ −^ +

− use calculus: take derivative with respect to and with respect to and then set the two resulting

equations equal to zero and solve for and (see NKNW pgs 19-20)

b 0 b 1 b 0 b 1

Least Squares Solution

− These are the best estimates for β 1 and β 0.

( )( )

( )

(^1 )

0 1

i i (^) XY

i X

X X Y Y SS

b X X SS

b Y b X

∑

∑

− These are also maximum likelihood estimators, see NKNW pp 30- − This estimate is the best because it is unbiased and minimum variance.

Maximum Likelihood

( ) 0 1 2

2 0 1 1 2

1 2

likelihood function

i i

i i Y X i

n

Y N X

f e

L f f f

− ⎛^ −β −β ⎞ ⎜⎝ (^) σ ⎟⎠

β + β σ

πσ = ⋅ ⋅…⋅ −

Find values for and which maximize L. These are the SAME as the least squares estimators

and !!!!

β 0 β 1 b 0 b 1

Estimation of σ^2

We also need to estimate with. We use the sum of the squared residuals, SSE, divided by the degrees of freedom n-2.

σ 2 s^2

( )

2 2 2

2

i i (^) i

E

Y Y (^) e s n n SSE MSE df

s s Root MSE

where is the sum of squared residuals or “errors”, and MSE stands for “mean squared

error”.

2 SSE = (^) ∑ e i

There will be other estimated variances for other quantities, and these will be denoted s 2 {other quantity}, e.g. s 2 {b1 }. Without any { }, s 2 refers to the value above, that is, the estimated variance of the residuals.

Identifying these things in the SAS Output

Analysis of Variance

Sum of Mean

Confidence Intervals

We are 100(1-α)% confident that the following interval contains μ:

W ± t s Wc { (^) } = ⎡⎣ W^ − t s Wc { (^) } , W + t s Wc { }⎤⎦

where t (^) c = t (^) ( 1 − 2 α, n − (^1) ) , the upper (^) ( 1 − α 2 )percentile of the t distribution with n-1 degrees of freedom,

and 1- α is the confidence level (e.g. 0.95 = 95%, so α = 0.05)

Significance tests

To test whether μ has a specific value, we use a t-test (one-sample, non-directional). H (^) 0 : μ = μ 0 vs Ha :μ ≠ μ 0

{ }

W 0

W

t s

− μ = has a t(n-1) distribution under H 0.

Reject H 0 if t ≥ t c^ , t c = t (^) ( 1 − α 2 , n − (^1) ).

P-value = Prob (^) H 0 ( T > t ) , where T ~ t n 1( - )

The p-value is twice the area in the upper tail of the t(n-1) distribution above the observed |t|. It is the probability of observing a test statistic at least as extreme as what was actually observed, when the null hypothesis is really true. We reject H 0 if P ≤ α.

Important notational comment

The text says “conclude HA” if t is in the rejection region (|t| ≥ t (^) c) , otherwise “conclude H 0 ”. This is shorthand for − “conclude HA” means “there is sufficient evidence in the data to conclude that H 0 is false, and so we assume that HA is true” − “conclude H 0 " means “there is insufficient evidence in the data to conclude that either H 0 or HA is true or false, so we default to assuming that H 0 is true”

Notice that a failure to reject H 0 does not mean that there was any evidence in favour of H 0.

NOTE

In this course α = 0.05 unless otherwise specified.

2.1: β 1 Inference

( {^ })

2 1 1 1 2 2 1

1 1 1 2 1

1

where

where b

t ~ t(n 2) if 0

X

X

b N b

b SS b t s b

s s SS

β σ

σ σ =

− β

− β =

According to our discussion above for “W”, you therefore know how to obtain CI’s and t-tests for β 1. (I’ll go through it now but not in the future.) There is one important difference: the df here are n – 2 not n – 1, because we are also estimating β 0.

Confidence Interval for β 1

− b 1 ± t s bc { 1 }

− where tc = t (^) ( 1 − 2 α, n − (^2) ), the upper 100 1( − α 2 )percentile of the t distribution with n – 2 degrees of

freedom − 1 – α is the confidence level

Significance tests for β 1

0 1 1 1 1 c c 0

: 0 vs : 0 b 0 t

Reject if t t , t t 1 2 n 2 Prob( T t ), where T~t(n 2)

H H a

s b

H α/ , P

β = β ≠ − =

2.2: β 0 Inference

( {^ })

2 0 0 0 2 2 2 0 X 0 0 0 2 2 0 2 0 X

b ~ , b

1 X where b n SS b t

for b replace by and take

1 X n SS t ~ t(n 2)

N

s b

s s

s b s

β σ

⎡ ⎤ σ = σ (^) ⎢ + ⎥ ⎣ ⎦ − β =

σ

Confidence Interval for β 0

− b 0^ ± t s bc { 0 }

− where tc = t (^) ( 1 − 2 α, n − (^2) ), 1- α is the confidence level

Summary of Inference

− Yi^ = β + β 0 1 Xi + ε i − (^) ( σ )are independent, random errors ~ 0,^2 ε i N

Parameter Estimators

For β 1 :

( )( )

( )

i i (^1 ) i

X X Y Y

b X X

∑

∑

β 0 : b 0 = Y −b X 1

σ^2 :

2 2 Yi^ b^0 b X^1 i n 2

s

∑

95% Confidence Intervals for β 0 and β 1

− b 1 ± t s bc { 1 }

− b 0 ± t s bc { 0 }

− where tc = t (^) ( 1 − 2 α, n − (^2) ), the 100 1( − α 2 )upper percentile of the t distribution with n-2 degrees of

freedom

Significance tests for β 0 and β 1

H 0 : β 0 = 0, H a: β 0 ≠ 0

0

~ 2 under H

b t t n s b

H 0 : β 1 = 0, H a: β 1 ≠ 0

1

~ 2 under H

b t t n s b

Reject H 0 if the P-value is small (<.05)

2.3 Power

The power of a significance test is the probability that the null hypothesis will be rejected when, in fact, it is false. This probability depends on the particular value of the parameter in the alternative space. When we do power calculations, we are trying to answer questions like the following: “Suppose that the parameter β 1 truly has the value 1.5 (say), and we are going to collect a sample of a particular size n and with a particular SSX. What is the probability that, based on our (not yet collected) data, we will reject H 0 ?”

Power for β 1

− H 0 :^ β 1 = 0,^ H a:^ β 1 ≠^0

−

1 1

b t s b

− tc = t (^) ( 1 − α 2 , n − (^2) )

− for α =.05 , we reject H 0 when t ≥ tc

− so we need to find P (^) ( t ≥ tc ) for arbitrary values of β 1 ≠ 0

− when β 1 = 0, the calculation gives α (H 0 is true) − t ~ t(n-2,δ) – noncentral t distribution: t-distribution not centered at 0

−

1 b 1

β δ = σ

is the noncentrality parameter: it represents on a “standardized” scale how far from true

H 0 is (kind of like “effect size”)

− We need to assume values for ( )

( )

2 2 (^1 ) i

b X X

σ σ = ∑ −

and n

− NKNW use tables, see pp 55- − we will use SAS

Example of Power for β 1

− Response Variable: Work Hours − Explanatory Variable: Lot Size − See page 21 for details of this study, pp 55-56 for details regarding power −

− we assume σ^2 =2500 , n=25 and SSX =19800, so we have ( )

( )

2 2 1 2 0. i

b X X

σ σ = = ∑ −

− consider β 1 = 1.

− we now can calculate

1 b 1

β δ = σ

− with t ~ t(n-2,δ); we want to find P(|t| ≥ tc) − we use a function that calculates the cumulative distribution function for the noncentral t distribution

See program nknw055.sas for the power calculations

data a1; n= 25 ; sig2= 2500 ; ssx= 19800 ; alpha= .05 ; sig2b1=sig2/ssx; df=n- 2 ; beta1= 1.5 ; delta=abs(beta1)/sqrt(sig2b1); tstar=tinv( 1 -alpha/ 2 ,df); power= 1 -probt(tstar,df,delta)+probt(-tstar,df,delta); output; proc print data=a1; run ;

Obs n sig2 ssx alpha sig2b1 df beta1 delta tstar power 1 25 2500 19800 0.05 0.12626 23 1.5 4.22137 2.06866 0.

data a2; n= 25 ; sig2= 2500 ; ssx= 19800 ; alpha= .05 ; sig2b1=sig2/ssx; df=n- 2 ; do beta1=- 2.0 to 2.0 by .05 ; delta=abs(beta1)/sqrt(sig2b1); tstar=tinv( 1 -alpha/ 2 ,df); power= 1 -probt(tstar,df,delta)+probt(-tstar,df,delta);

Application of the Theory

( ) We estimate σ^2 { Y ˆ h }by (^) { } ( )

2 2 2 h 2 i

ˆ^1 X^ X

n (^) X X

s Y h s

= ⎢^ + ⎥

⎣ ∑ ⎦

It follows that h h

ˆ E(Y )

t ~ t ( ˆ )

h (

Y

s

μ

n − 2 ); proceed as usual.

95% Confidence Interval for E(Yh)

ˆ (^) { ˆ} c Yh ± t s Yh where t c (^) = t(.975, n-2)

NOTE: significance tests can be performed for Y ˆ h but they are rarely used in practice

Example

See program nknw060.sas for the estimation of subpopulation means. The option “clm” to the model

statement asks for c onfidence l imits for the m ean Y ˆ h.

data a1; infile 'H:\Stat512\Datasets\Ch01ta01.dat'; input size hours; data a2; size= 65 ; output; size= 100 ; output; data a3; set a1 a2; proc print data=a3; run ; proc reg data=a3; model hours=size/clm; id size; run ; Dep Var Predicted Std Error Obs size hours Value Mean Predict 95% CL Mean 25 70 323.0 312.2800 9.7647 292.0803 332. 26 65. 294.4290 9.9176 273.9129 314. 27 100. 419.3861 14.2723 389.8615 448.

PPT 4

2.5: Prediction of Yh(new)

We wish to construct an interval into which we predict the next observation (for a given Xh ) will fall.

− The only difference between this and E Y ( h )is that the variance is different.

− In prediction, we have two variance components: (1) variance associated with the estimation of the

mean response and (2) variability in a single observation taken from the distribution with that mean.

Y^ ˆ h

− Yh new (^) ( ) = β + β 0 1 Xh + εis the value for a new observation with X = Xh.

We estimate Yh(new) starting with the predicted value. This is the centre of the confidence interval,

just as it was for E(Yh ). However, the width of the CI is different because they have different variances.

Yh

( ( )) ( ) ( )^ ε

h new^ h

h

Var Y Var Y Var

s pred s Y s

2 2 2 h 2 i

1 X^ X

pred 1 n (^) X X

= ⎢^ + + ⎥

s s

Y h new Yh (^) t n s pred

− s{pred} denotes the estimated standard deviation of a new observation with X = Xh. It takes into

account variability in estimating the mean as well as variability in a single observation from a distribution with that mean.

Y^ ˆ h

Notes

The procedure can be modified for the mean of m observations at X=Xh (see 2.39a on page 66)

Standard error is affected by how far Xh is from X (see Figure 2.3). As was the case for the mean response, prediction is more accurate near X.

See program nknw065.sas for the prediction interval example. The “cli” option to the model statements asks SAS to give c onfidence l imits for an i ndividual observation. (c.f. clb and clm)

data a1; infile 'H:\Stat512\Datasets\Ch01ta01.dat'; input size hours; data a2; size= 65 ; output; size= 100 ; output; data a3; set a1 a2; proc reg data=a3; model hours=size/cli; run ;

Dep Var Predicted Std Error Obs size hours Value Mean Predict 95% CL Predict Residual 25 70 323.0000 312.2800 9.7647 209.2811 415.2789 10. 26 65. 294.4290 9.9176 191.3676 397.. 27 100. 419.3861 14.2723 314.1604 524..

Notes

The standard error (Std Error Mean Predict ) given in this output is the standard error of , not

s {pred}. (That’s why the word mean

Y^ ˆ h is in there). The CL Predict label tells you that the confidence

interval is for the prediction of a new observation.

The prediction interval for is wider than the confidence interval for because it has a larger

variance.

Yh new (^) ( ) Y ˆ h

PPT

Estimation of E(Yh) compared to Prediction of Yh

0 1

Yh b b Xh

{ }

2 (^2 2) h 2 i 2 (^2 2) h 2 i

ˆ^1 X^ X

n X X

1 X X pred 1 n (^) X X

( ) ( )

( ) ( )

s Y h s

s s

∑

∑

See program nknw067x.sas for the clm (mean) and cli (individual) plots. data a1; infile 'H:\Stat512\Datasets\Ch01ta01.dat'; input size hours; Confidence intervals: symbol1 v=circle i=rlclm95; proc gplot data=a1; plot hours*size; run ;

Prediction intervals: symbol1 v=circle i=rlcli95; proc gplot data=a1; plot hours*size; run ;

2.7: Analysis of Variance (ANOVA) Table

Organize results arithmetically

Total sum of squares in Y is (^) ( )

2 SS Y = (^) ∑ Yi − Y

Partition this into two sources

  • Model (explained by regression)
  • Error (unexplained / residual)