The main objective of many statistical investigations is to make predictions.
For instance, an engineer may wish to predict the amount of oxide that will form on the surface of a metal baked in an oven for one hour at 200∘C, or the amount of deformation of a ring subjected to a certain compressive force.
Usually, such predictions require a formula which relates the dependent variable whose value we want to predict (or called response) to one or more other variables, usually called predictors (or regressors).
The collection of statistical tools for this is called regression analysis.
Simple Linear Regression
The simplest form of regression analysis is simple linear regression, which involves a single predictor and a single response variable.
Y=β0+β1X+e
where:
Y is the response variable.
X is the predictor variable.
β0 is the intercept.
β1 is the slope.
Assume that E(e)=0 and Var(e)=σ2.
Suppose we fix X=x, meaning
Y=β0+β1x+e,
with mean E(Y)=β0+β1x and variance Var(Y)=σ2 (Y is normal if e is normal).
The linear function β0+β1x is thus the function giving the mean value of Y for each possible value of X.
It is called the regression function (or regression line) and will be denoted as,
μY∣X=x=E(Y∣X=x)=β0+β1x.
The slope β1 is the change in mean of Y for one unit change in X, the intercept β0 is the mean value of Y when X=0.
Least Squares Estimator
Gauss proposed estimating β0 and β1 to minimize the sum of the squares of the vertical deviations between the observed responses and the fitted line.
These deviations are called the residuals.
The residuals are the vertical distances between the data points and the fitted line.
For any “candidate” straight line Y=a+bX, we can write R(a,b)=∑i=1N(Yi−(a+bXi))2.
A prediction interval for Y at X=x will always be longer than the CI for μY∣X=x because there is much more variability in one observation than in an average.
As n gets larger (n→∞), the width of CI for μY∣X=x decreases to 0, buy this is not the case for the prediction interval.
Analysis of Variance (ANOVA)
The most interesting test for simple linear regression is probably,
H0:β1=0vs.H1:β1=0.
We previously used t-test,
s/sxxβ1^∼tn−2.
There is an alternative (and equivalent) test, the F-test based on analysis of variance.
Except for its sign (positive or negative linear relationship), the sample correlation is the square root of the coefficient of determination.
Example
A food processing center needs to be able to switch from one type of package to another quickly to react to changes in order patterns.
Consultants have developed a new method for changing the production line.
We have a sample of 48 change-over times using the new method, and an independent sample of 72 change-over times for the existing method.
We model the relationship between Y, the change-over time and X, the dummy variable for the new method.
We consider the simple linear regression model,
Y=β0+β1X+e,
where Y= change over time and x is the dummy variable (i.e., x = 1 for the new change-over method and 0 for the existing method).
So far we have assumed independence, linearity, constant variance and normal error.
But, we will now look at some techniques and tools to check these assumptions.
We will discuss the following,
Leverage points
If they exist, determine if they are bad leverage points.
Standardized residuals
Outliers
Examine assumption of constant variance
Examine whether the errors are normally distributed
Leverage Points
A leverage point is a point whose x-value is distant from the other x-values.
A point is a bad leverage point if its y-value does not follow the pattern set by the other data points.
In other words, a bad leverage point is a leverage point which is also an outlier.
The mathematical definition of leverage is,
yi^=j=1∑nhijyj,
where hij=[n1+Sxx(xi−xˉ)(xj−xˉ)].
We can see that, if we sum up hij for all j,
j=1∑nhij=1.
Thus,
hii=n1+∑j=1n(xj−xˉ)2(xi−xˉ)2,
is called the leverage of the i-th data point.
If hii≈1,yi^≈yi.
A popular rule of thumb for detecting leverage points is,
hii>2×average(hii).=2×n2=n4.
When dealing with bad leverage points, after finding them we will remove them and then fit a different model.
Standardized Residuals
It can be shown that,
Var(ei^)=σ2(1−hii).
This is reasonable since hii≈1 implies that yi^≈yi and thus ei^ is small.
The standardized residuals are defined as,
ri=s1−hiiei^.
where s=n−21∑j=1nej^2.
Outliers
The common practice of labelling points as outliers is,
If the standardized residual for the point falls outside the interval from -2 to 2, it is considered an outlier.
In very large data sets, we change this interval to -4 to 4.
In R, we can use the following code to find the leverage and standardized residuals,
1
leverage<-hatvalues(m1)
2
# or influence(m1)$hat
3
4
stdres<-rstandard(m1)
5
res<-m1$residuals
6
# or residuals(m1)
Cook’s Distance
Cook’s distance is a measure of the influence of each observation on the fitted values.
where yj(i)^ denotes the j-th fitted value when the i-th observation is deleted.
A recommended cutoff is 4/(n−2).
Normality of Errors
Usually the approximation ei^≈ei is accurate enough to justify use of a QQ-plot.
Non-constant Variance
What do we do if the variance is not constant?
We can use a transformation, the transformation is used to overcome problems due to non-constant variance but also due to nonlinearity.
The methods that we will discuss deal with positive variables only.
There is no general rule of transformation, if for example we have count data, this is often modelled by the Poisson distribution.
Thus, the appropriate transformation is square root.
For overcoming nonlinearity, we need to think a bit more.
Suppose the true model is Y=g(β0+β1x+e) for an unknown monotone function g.
We can rewrite this as,
g−1(Y)=β0+β1x+e.
For possibleg, we can consider the family of scaled power transformations,
ψs(Y,λ)={(Yλ−1)/λ,log(Y),if λ=0,if λ=0.
So, the procedure will be,
Fit a linear regression model yi=β0+β1xi+ei.
Estimate g−1 by plotting yi^=β^0+β^1xi against xi.
Mathematically, we minimize∑i(yi^−α0−α1ψ(yi,λ))2 over (α0,α1,λ).