Exercise 6
Exercise 6
The report (it can be an Excel file) should include also verbal explanations, in addition to calculations. Also
remember to answer all questions which require verbal answers.
1. A mountain hiker walked from coast to the mountains and measured air temperature in different
altitudes. The results are below. Let’s make an unrealistic assumption that the hiker walks very quickly
(so that sun is not setting during the hike) and weather is stable, when the decrease in temperature is
mainly caused by change in altitude.
alt. ( km ) temp. ( C )
0,0 37,7
0,5 34,3
1,0 25,0
1,5 23,2
2,0 14,3
2,5 11,1
3,0 8,8
a) Create a scatter plot of the data in Excel. Fit a line to the data, using Add Trendline tool. Set the
equation and the R-squared value to be shown in the graph.
b) Add Trendline tool has option “Forecast”. Use it to predict the temperature in higher altitudes. If
assuming that the same linear model can be used, what would be the temperature on the top of Mont
Blanc (4810 m) ?
c) Try different models with Add Trendline: polynomials of degree 2, 3, 4 and so on. What happens to
R-squared value (and why)? What about the predicted temperature on the top of Mont Blanc? What
about the predictions based on different polynomials?
d) Fit 2nd degree polynomial to the data using Excel’s Solver (and using the method of least squares).
Is the solution the same as in point c ?
Additional voluntary problem: Solve the same problem with matrix algebra, using Matlab software or
similar free software Gnu Octave, which you can install on your own laptop from website
https://www.gnu.org/software/octave/ . Find the parameters a, b and c using Matlab/Octave and the
method based on matrices and formula
𝑋 = (𝐴𝑇 𝐴)−1 𝐴𝑇 𝐵
Make a graph of observed and modelled data. The solving process is very similar to the one in file
curve_fitting.m.
3.
a) The data below is to be modelled with function 𝑦 = 𝑎 ⋅ 𝑥 𝑏 + 𝑐. Using Solver and the method of
least squares, find optimal values for parameters 𝑎, 𝑏 and 𝑐.
x 0,2 0,6 1 1,4 1,8 2,2 2,6 3 3,4 3,8 4,2 4,6
y 11 33 41 89 155 203 335 469 599 775 1035 1299
b) Using the same idea as in file Simple_Linear_Regression.xlsx, determine R-squared value in this
case.
4.
b) Applying regression, try to explain variable Salary by variable Sales (this is one-variable regression,
but use Regression tool in Data Analysis toolpak).
Observe how the R-square value changes. When the number of variables is increased it’s better to use
Adjusted R Square which considers also the number of variables. Ordinary R-square value always
improves (or sometimes stays unchanged) when new variables are added, even if the variables had
nothing to do with the variable to be explained.
d) There is one sales agent whose numbers seem to be somewhat contradictory. How the results of
point b (especially case b3) are changed if data of this sales agent is removed and regression
analysis is repeated? Tell about your observations in your report.