2 More general regression model Consider one Y variable and n independent variables Xi, e.g. X1, X2, X3.Data on n tuples (yi, xi1,xi2,xi3).Scatter plots show linear association between Y and the X-variablesThe observations on y can be assumed to satisfy the following modelDataerrorPrediction
3 Assumptions on the regression model The relationship between the Y-variable and the X-variables is linearThe error terms ei (measured by the residuals)have zero mean (E(ei)=0)have the same standard deviation e for each fixed xare approximately normally distributed - Typically true for large samples!are independent (true if sample is S.R.S.)Such assumptions are necessary to derive the inferential methods for testing and prediction (to be seen later)!WARNING: if the sample size is small (n<50) and errors are not normal, you can’t use regression methods!
4 Parameter estimatesSuppose we have a random sample of n observations on Y and on p-1 independent X-variables.How do we estimate the values of the coefficients ’s in the regression model of Y versus the X-variables?
5 Regression Parameter estimates The parameter estimates are those values for ’s that minimize the sum of the square errors:Thus the parameter estimates are those values for ’s that will make the model residuals as small as possible!The fitted model to compute predictions for Y is
6 Using Linear Algebra for model estimation (section 12.9) Let be the parameter vector for the regression model in p variables.The parameter estimates for each beta can be efficiently found using linear algebra aswhere X is the data matrix for the X-variables and Y is the data vector for the response variable.Hard to compute by hand – better use a computer!XT is the transpose of matrix XX-1 denotes the inverse of matrix X
7 EXAMPLE: CPU usageA study was conducted to examine what factors affect the CPU usage. A set of 38 processes written in a programming language was considered. For each program, data were collected on theY = CPU usage (time) in seconds of time,X1= the number of lines (linet) in thousands generated by the process execution.X2 = number of programs (step) forming the processX3 = number of mounted computer devices (device).Problem: Estimate the regression model of Y on X1,X2 and X3
8 I) Exploratory data step: Are the associations between Y and the x-variables linear? Draw the scatter plot for each pair (Y, Xi)CPU timeCPU timeLines executed in processNumber of programsCPU timeDo the plots showlinearity?Mounted devices
9 The REG Procedure Parameter Estimates PROC REG - SAS OUTPUTThe REG Procedure Parameter EstimatesParameter StandardVariable Label DF Estimate Error t Value Pr > |t|InterceptLinet <.0001step <.0001deviceThe fitted regression model is
10 Fitted model The fitted regression model is The ’s estimated values measure the changes in Y for changes in X’s.For instance, for each increase of 1000 lines executed by the process (keeping the other variables fixed), the CPU usage time will increase of seconds.Fixing the other variables, what happens on the CPU time if I add another device?
11 Interpretation of model parameters In multiple regressioncoefficient value of an X variable measures the predicted change in Y for any unit increase in that X-variable while the other independent variables stay constant.For instance: measures the changes in Y for a unit increase of the variable X2 if the other x-variables X1 and X3 are fixed.
12 Are the estimated values accurate? Residual Standard Deviation (pg. 632)Testing effects of individual variables (pg )
13 How do we measure the accuracy of the estimated parameter values How do we measure the accuracy of the estimated parameter values? (page 632)For a simple linear regression with one X, the standard deviation of the parameter estimates are defined as:They are both functions of the error variance regarded as asort of standard deviation (spread) of the points around the line!The error variance is estimated by the residual standard deviation se (a.k.a. root mean square error )Residuals!
14 How do we interpret residual standard deviation? Used as a coarse approximation of the prediction error for new y-values.Probable error in new predictions is+/- 2 sese also used in the formula of standard errors of parameter estimates:they can be computed from the data and measure the noise in the parameter estimates
15 For general regression models with k x-variables For k predictors, the standard errors of the parameter estimates have a complicated form…but they still depend on the error standard deviation !The residual standard deviation or root mean square error is defined ask+1 = number of parameters ’sThis measures the precision of our predictions!
16 The REG ProcedureAnalysis of VarianceSum of MeanSource DF Squares Square F Value Pr > FModel <.0001ErrorCorrected TotalRoot MSE R-SquareDependent Mean Adj R-SqCoeff VarThe root mean square error for the CPU usage regression model is computed above. That gives an estimate of the error standard deviationse=
17 Inference about regression parameters! Regression estimates are affected by random errorThe concepts of hypothesis testing and confidence intervals apply!The t-distribution is used to construct significance tests and confidence intervals for the “true” parameters of the population.Tests are often used to select those x-variables that have a significant effect on Y
18 Tests on the slope for straight line regression Consider the simple straight line case.A common test on the slope is the test on the hypothesis“X has no effect on Y” or the slope is equal to zero!Or in statistical terms :X has a negative effectHo: vs Ha: X has a significant effectX has a positive effectThe test is given by the t-statisticWith t-distribution with n-2 degrees of freedom!
19 Tests on the parameters in multiple regression Assumptions on the data:1. e1, e2, … en are independent of each other.2. The ei are normally distributed with mean zero and have common variance s.Significance Tests on parameter test hypothesis:“Xj has no effect on Y” or in statistical termsXj has a negative effect on YXj has a significant effect on YXj has a positive effect on YThe test is given by the t-statisticwith t-distribution with n-(k+1) degrees of freedomComputed by SAS
20 Tests in SASThe test p-values for regression coefficients are computed by PROC REGSAS will produce the two-sided p-value.If your alternative hypothesis is one-sided (either > or < ), then find the one-sided p-value dividing by 2 the p-value computed by SASone-sided p-value = (two-sided p-value)/2
21 The REG Procedure Parameter Estimates SAS OutputThe REG Procedure Parameter EstimatesParameter StandardVariable Label DF Estimate Error t Value Pr > |t|InterceptLinet <.0001step <.0001deviceP-valueT-statistic valueT-tests on each parameter value show that all the x-variables in the model are significant at 5% level (p-values <0.05).The null hypothesis of no effect can be rejected, and we conclude that there is a significant association between Y and each x-variable.
22 Test on the intercept 0The REG Procedure Parameter EstimatesParameter StandardVariable Label DF Estimate Error t Value Pr > |t|InterceptLinet <.0001step <.0001deviceThe test on the intercept says that the null hypothesis of 0=0 should be accepted. The test p-value isThis means that the model should have no intercept !This is not recommended though – unless you know that Y=0 if all the x-variables are equal to zero.
23 What do we do if a model parameter is not significant? If the t-test on a parameter bj shows that the parameter value is not significantly different from zero, we should refit the regression model without the x-variable corresponding to bj.
24 SAS Code for the CPU usage data Data cpu;infile "C:\week5\cpudat.txt";input time line step device;linet=line/1000;label time="CPU time in seconds" line="lines in program execution" step="number of computer programs" device="mounted devices" linet="lines in program (thousand)";/*Exploratory data analysis *//* computes correlation values between all variables indataset */proc corr data=cpu;run;/* creates scatterplots between time vs linet, time vs step and time vs device, respectively */proc gplot data=cpu;plot time*(linet step device);
25 model time=linet step device / noint; /* Regression analysis: fits model to predict time using linet, step and device*/proc reg data=cpu;model time=linet step device;plot time*linet /nostat ;run; quit;If you want to fit a model with no intercept use the following model statement:model time=linet step device / noint;