1.7: Regression Analysis
- Page ID
- 9465
\( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)
\( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)
\( \newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\)
( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\)
\( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)
\( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\)
\( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)
\( \newcommand{\Span}{\mathrm{span}}\)
\( \newcommand{\id}{\mathrm{id}}\)
\( \newcommand{\Span}{\mathrm{span}}\)
\( \newcommand{\kernel}{\mathrm{null}\,}\)
\( \newcommand{\range}{\mathrm{range}\,}\)
\( \newcommand{\RealPart}{\mathrm{Re}}\)
\( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)
\( \newcommand{\Argument}{\mathrm{Arg}}\)
\( \newcommand{\norm}[1]{\| #1 \|}\)
\( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)
\( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\AA}{\unicode[.8,0]{x212B}}\)
\( \newcommand{\vectorA}[1]{\vec{#1}} % arrow\)
\( \newcommand{\vectorAt}[1]{\vec{\text{#1}}} % arrow\)
\( \newcommand{\vectorB}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)
\( \newcommand{\vectorC}[1]{\textbf{#1}} \)
\( \newcommand{\vectorD}[1]{\overrightarrow{#1}} \)
\( \newcommand{\vectorDt}[1]{\overrightarrow{\text{#1}}} \)
\( \newcommand{\vectE}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash{\mathbf {#1}}}} \)
\( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)
\( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)
\(\newcommand{\avec}{\mathbf a}\) \(\newcommand{\bvec}{\mathbf b}\) \(\newcommand{\cvec}{\mathbf c}\) \(\newcommand{\dvec}{\mathbf d}\) \(\newcommand{\dtil}{\widetilde{\mathbf d}}\) \(\newcommand{\evec}{\mathbf e}\) \(\newcommand{\fvec}{\mathbf f}\) \(\newcommand{\nvec}{\mathbf n}\) \(\newcommand{\pvec}{\mathbf p}\) \(\newcommand{\qvec}{\mathbf q}\) \(\newcommand{\svec}{\mathbf s}\) \(\newcommand{\tvec}{\mathbf t}\) \(\newcommand{\uvec}{\mathbf u}\) \(\newcommand{\vvec}{\mathbf v}\) \(\newcommand{\wvec}{\mathbf w}\) \(\newcommand{\xvec}{\mathbf x}\) \(\newcommand{\yvec}{\mathbf y}\) \(\newcommand{\zvec}{\mathbf z}\) \(\newcommand{\rvec}{\mathbf r}\) \(\newcommand{\mvec}{\mathbf m}\) \(\newcommand{\zerovec}{\mathbf 0}\) \(\newcommand{\onevec}{\mathbf 1}\) \(\newcommand{\real}{\mathbb R}\) \(\newcommand{\twovec}[2]{\left[\begin{array}{r}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\ctwovec}[2]{\left[\begin{array}{c}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\threevec}[3]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\cthreevec}[3]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\fourvec}[4]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\cfourvec}[4]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\fivevec}[5]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\cfivevec}[5]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\mattwo}[4]{\left[\begin{array}{rr}#1 \amp #2 \\ #3 \amp #4 \\ \end{array}\right]}\) \(\newcommand{\laspan}[1]{\text{Span}\{#1\}}\) \(\newcommand{\bcal}{\cal B}\) \(\newcommand{\ccal}{\cal C}\) \(\newcommand{\scal}{\cal S}\) \(\newcommand{\wcal}{\cal W}\) \(\newcommand{\ecal}{\cal E}\) \(\newcommand{\coords}[2]{\left\{#1\right\}_{#2}}\) \(\newcommand{\gray}[1]{\color{gray}{#1}}\) \(\newcommand{\lgray}[1]{\color{lightgray}{#1}}\) \(\newcommand{\rank}{\operatorname{rank}}\) \(\newcommand{\row}{\text{Row}}\) \(\newcommand{\col}{\text{Col}}\) \(\renewcommand{\row}{\text{Row}}\) \(\newcommand{\nul}{\text{Nul}}\) \(\newcommand{\var}{\text{Var}}\) \(\newcommand{\corr}{\text{corr}}\) \(\newcommand{\len}[1]{\left|#1\right|}\) \(\newcommand{\bbar}{\overline{\bvec}}\) \(\newcommand{\bhat}{\widehat{\bvec}}\) \(\newcommand{\bperp}{\bvec^\perp}\) \(\newcommand{\xhat}{\widehat{\xvec}}\) \(\newcommand{\vhat}{\widehat{\vvec}}\) \(\newcommand{\uhat}{\widehat{\uvec}}\) \(\newcommand{\what}{\widehat{\wvec}}\) \(\newcommand{\Sighat}{\widehat{\Sigma}}\) \(\newcommand{\lt}{<}\) \(\newcommand{\gt}{>}\) \(\newcommand{\amp}{&}\) \(\definecolor{fillinmathshade}{gray}{0.9}\)What is Regression Analysis?
Suppose we calculate some variable of interest, y, as a function of some other variable x. We call y the dependent variable and x the independent variable. For example, consider the data set below, taken from a simple experiment involving a vehicle, its velocity versus time is tabulated. In this case, velocity is a function of time, thus velocity is the dependent variable and the time is the independent variable.
Time [s] | Velocity [m/s] |
0 | 20 |
10 | 39 |
20 | 67 |
30 | 89 |
40 | 111 |
50 | 134 |
60 | 164 |
70 | 180 |
80 | 200 |
Vehicle velocity versus time.
In its simplest form regression analysis involves fitting the best straight line relationship to explain how the variation in a dependent variable, y, depends on the variation in an independent variable, x. In our example above, once the relationship (in this case a linear relationship) has been estimated we can produce a linear equation in the following form:
\(y=m x+n\)
And once an analytic equation such as the one above has been determined, dependent variables at intermediate independent values can be computed.
Performing Linear Regression
Regression analysis with MATLAB is easy. The MATLAB Basic Fitting GUI allows us to interactively to do "curve fitting" which is a method to arrive at the best "straight line" fit for linear equations or the best curve fit for a polynomial up to the tenth degree. The procedure to perform a curve fitting with MATLAB is as follows:
- Input the variables,
- Plot the data,
- Initialize the Basic Fitting GUI,
- Select the desired regression analysis parameters.
Using the data set above, determine the relationship between velocity and time.
First, let us input the variables (Workspace > New variable) as shown in the following figures.
Figure \(\PageIndex{1}\). A new variable is created in the Workspace.
Figure \(\PageIndex{2}\). New variables are entered in the Variable Editor.
Second, we will plot the data by typing in plot(time,velocity)
at the MATLAB prompt. The following plot is generated, select Tools > Basic Fitting:
Figure \(\PageIndex{3}\). A plot is generated in Figure 1. The Basic Fitting tool can be initialized from Tools > Basic Fitting.
In the "Basic Fitting" window, select "linear" and "Show equations". The best fitting linear line along with the corresponding equation are displayed on the plot:
Figure \(\PageIndex{4}\). Basic Fitting window is used to select the desired regression analysis parameters.
Now let us do another curve fitting and obtain an equation for the function. Using that equation, we can evaluate the function at a desired value with polyval
.
The following is a collection of data for an iron-constantan thermocouple (data available for download). 1
Temperature [C] | Voltage [mV] |
50 | 2.6 |
100 | 6.7 |
150 | 8.8 |
200 | 11.2 |
300 | 17.0 |
400 | 22.5 |
500 | 26 |
600 | 32.5 |
700 | 37.7 |
800 | 41 |
900 | 48 |
1000 | 55.2 |
Temperature [C] vs Voltage [mV]
- Plot a graph with Temperature as the independent variable.
- Determine the equation of the relationship using the Basic Fitting tools.
- Estimate the Voltage that corresponds to a Temperature of 650 C and 1150 C.
We will input the variables first
Voltage=[2.6;6.7;8.8;11.2;17;22.5;26;32.5;37.7;41;48;55.2]
Voltage=[2.6;6.7;8.8;11.2;17;22.5;26;32.5;37.7;41;48;55.2]
To plot the graph, type in:
plot(Temp,Voltage)
We can now use the Plot Tools and Basic Fitting settings and determine the equation:
Figure \(\PageIndex{5}\). Basic Fitting window is used to select the desired regression analysis parameters.
By clicking the right arrow twice at the bottom right corner on the Basic Fitting window, we can evaluate the function at a desired value. See the figure below which illustrates this process for the temperature value 1150 C.
Figure \(\PageIndex{6}\). Estimating the Voltage that corresponds to a Temperature of 1150 C.
Now let us check our answer with a technique we learned earlier. As displayed on the plot, we have obtained the following equation:\(y=0.052831 x+0.67202\) This equation can be entered as polynomial and evaluated at 650 and 1150 as follows:
>> p=[0.052831,0.67202] p = 0.0528 0.6720 >> polyval(p,1150) ans = 61.4277
Summary of Key Points
- Linear regression involves fitting the best straight line relationship to explain how the variation in a dependent variable, y, depends on the variation in an independent variable, x,
- Basic Fitting GUI allows us to interactively perform curve fitting,
- Some of the plot fits available are linear, quadratic and cubic functions,
- Basic Fitting GUI can evaluate functions at given points.
Footnotes
- 1 Engineering Fundamentals and Problem Solving by Arvid R. Eide, Roland Jenison, Larry L. Northup, Steven K. Mikelson , McGraw-Hill Higher Education. © 2007 p.114