
This program will use a
class.
It will do a statistical
line of best fit, more commonly called LINEAR REGRESSION LINE
class growth
{ public:
apvector<int> age; //declare
with NO size
apvector<float> height; //do a RESIZE later
apvector<float> y_hat;
apvector<float> residual;
}data;
Here is the data_ height of
girls at a certain age
Enter the data any way you
choose: cin, file read, constructor, or initializer list. (I suggest cin or
create your own file)
AGE HEIGHT
2
86.5
3
95.5
4
103.0
5
109.8
6
116.4
7
122.4
8
128.2
9
133.8
10
139.6
11
145.0
Look
at pages 548-555 in the old stat book for calculations
*The apvector size is 11.
(one extra space)
*Have your program calculate
r the correlation coefficient. (see below)
*Have the program also
calculate the linear regression equation(least-square line).
*You must use the least
square formulas below.
*Next, your program will
store to the third and fourth members of data. The Y HAT and then the residual.
These are the observed value minus predicted value…
data[x].height – Y_HAT[x].
You must get age and height in first.
*Print
out the chart, maybe with a member function. (only even years)
AGE HEIGHT Y-HAT RESIDUAL
2 86.5 89.37 -2.87
4 103.0 102.1 .89
6 116.4 108.2 1.56
8 128.2 127.57 .63
10 139.6 140.3 -.70 Least square line: y=76.641 x 6.366 age
Use your least square
equation to EXTRAPOLATE height for year 12,13,14 and 15
Calculate standard
deviation of age and height, ave age, ave height.
Standard deviation needs
the mean. It is the sqrt of (sum of differences of each value from the mean
squared divided by n-1)
{correlation coef= r= (xy
– x*y)/sn*sy x n/(n-1) resid= ob-calc b=r sy/sy a=y-bx
Yhat=a = b x } yhat means
the predicted value for height given some age