Starting from:

$29.99

Assignment #2 linear regression least-squares method

CST 8233- Assignment #2
linear regression least-squares method
Earnings: 8% of your final grade
NOTE: Plan to finish a few days early to avoid last minute hardware/software holdups for
which no allowance is given.
NOTE: The code in this assignment must be your own work. It must not be code taken from
another student or written for you by someone else, even if you give a reference to the person
you got it from (attribution); if it is not entirely your own work it will be treated as plagiarism
and given a fail mark, or less.
Purpose: Fit data using linear regression least-squares method for an exponential function.
Discussion: A hospital administrator wished to develop a regression model for predicting the
degree of long-term recovery after discharge from the hospital for severely injured patients.
The predictor variable to be utilized is number of days of hospitalization (X), and the response
variable is a prognostic index for long-term recovery (Y), with large values of the index
reflecting a good prognosis. Data for 15 patients were studied and are presented in a file Related
earlier studies reported in the literature found the relationship between the predictor variable
and the response variable to be exponential. Hence, it was decided to investigate the
appropriateness of the two-parameter nonlinear exponential regression mode.
Days Prognostic_index
2 54
5 50
7 45
10 37
14 35
19 25
26 20
31 16
34 18
38 13
45 8
52 11
53 8
60 4
65 6
For the data in the file, the function has the form 𝑁 = 𝑎𝑒
𝑏𝑥 where 𝑎 and 𝑏 are constants that are
determined from the fit. Until the user wishes to quit the application should do the following:
• Read data from a file
• Do an exponential fit
• Offer an interpolation/extrapolation of both the prognostic index and its rate of decrease
The basic formulas are fits to the straight-line equation 𝑦 = 𝑚𝑥 +𝑐, so the exponential data has to be
transformed to have this linear relation. With the transformed data solve the least-squares linear
regression formulas to get solutions for 𝑚 and 𝑐 and then convert them back to 𝑎 and 𝑏. Then using
the exponential formula with 𝑎 and 𝑏, offer the user the option of interpolating / extrapolating the data
to find what the prognostic index and rate of decrease will be in other days.
What to Submit: Use Brightspace to submit this assignment as a zip file (not RAR, not 9zip, not 7
zip) containing only the source code file (ass2.cpp). The name of the zipped folder must contain your
name as a prefix so that I can identify it, for example using my name the file would be
kadriaAss2CST8233.zip. It is also vital that you include the file header (as specified in the Submission
Standard) so the file can be identified as yours. Use comment lines in the file to include the header.
There is a late penalty of 25% per day - even one minute is counted late.
You may lose 60% or more if:
⚫ The output is wrong
⚫ Your application won’t build in Visual Studio 2019
⚫ Your application crashes in normal operation
⚫ I can’t build it because you submitted the wrong files or the files are missing, even if it’s an
honest mistake – this gets 100% deduction.
Don’t send me the file as an email attachment – it will get 0.
Example Output
Example output is given below. Yours should be the same. Note than your assignment might be
tested with different interpolation / extrapolation parameters than those shown.
LEAST_SQUARES LINEAR REGRESSION
MENU
1. Exponential Fit
2. Quit
1
Please enter the name of the file to open: data.txt
Days Prognostic_index
2 54
5 50
7 45
10 37
14 35
19 25
26 20
31 16
34 18
38 13
45 8
52 11
53 8
60 4
65 6
There are 15 records.
Linear Regression Fit: Prognostic_index = 56.7*exp -0.038*days
MENU
1. Extrapolation
2. Main Menu
1
Please enter the days to extrapolate to: 33
days = 33
Prognostic_index = 16.2
rate of decrease = -0.615
MENU
1. Extrapolation
2. Main Menu
1
Please enter the days to extrapolate to: 73
days = 73
Prognostic_index = 3.54
rate of decrease = -0.135
MENU
1. Extrapolation
2. Main Menu
2
LEAST_SQUARES LINEAR REGRESSION
MENU
1. Exponential Fit
2. Quit

More products