lin reg assignment

Upload: yusef-vazirabad

Post on 10-Apr-2018

224 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/8/2019 Lin Reg Assignment

    1/2

    Project 3 Functions (Simulation, Random Numbers & Linear Regression)

    BE-2200, Dr. C. S. Tritt, Fall '10 (v. 1.0)

    Due: Start of Lecture, 10/18/10

    Simulation, statistics and data visualization are all commonly used in biomedical and biomolecular engineering.

    In this project, you will create: 1) a function that creates a simulated data set (a linear relationship with noise);

    2) another function to perform a linear regression on this data to obtain the slope and intercept of the best fit

    line representing it; and 3) a third function, that plots the data and its regression line. You will also create a

    driver program to test and demonstrate the operation of each of these functions.

    Data Generation (Simulation Simulation) linGen.m

    Write a function that, given independent data vectorx, slope m, intercept b, noise epsilon and random stream rs

    parameters, returns a dependent data vector y. The pseudocode relationship for the dependent values is y

    mx+ b + epsilon*z where z is the standard normal distribution (which the Matlab function randn draws from

    stream rs).

    Data Analysis (Statistical Analysis) linReg.m

    Write a function that, given independent and dependent data vectorsxand y(respectively) returns the slope

    and intercept of the line that best fits (in terms of minimizing the sum square error) this data. See Example 8.5

    in Chapman for a full explanation of the method. Important quantities and equations follow:

    x = Sum ofx(independent) values.

    y = Sum ofy(dependent) values.2

    x = Sum of the squares of thexvalues (note: square before summing).

    xy = Sum of the products of correspondingx, ypairs.

    x = mean ofxvalues =

    xn

    y = mean ofyvalues =

    xn

    The slope is then:2

    xy y xm

    x x x

    And the intercept: b y mx

  • 8/8/2019 Lin Reg Assignment

    2/2

    Plot Results ( Data Visualization) linPlot.m

    Write a function that, given data vectorsxand yand regression parameters m and b, plots the data and the best

    fit line through it (as shown in the example below). The horizontal (x) limits on the regression line should be the

    minimum and maximum values in the independent data vectorx.

    Sample Command Window Dialog and Plot

    Enter desired slope (arbitrary units): 0.5

    Enter desired intercept (arbitrary units): 8.0

    Enter desired noise parameter (arbitrary units): 1.5

    Regression results: slope = 0.495589, intercept = 7.982158

    Driver Program & Deliverables (Function Testing & Documentation) linProject.m

    The driver program should create the independent data vector,x. This data should range from -10 to 10 and

    include 101 values. It may be a simple sequence of values or a collection of uniformly distributed random values.

    Be sure to state which in your documentation. It should than prompt the user for slope, intercept and noise

    parameters. Finally, it should call the functions linGen, linReg and linPlotin sequence and correctly manage the

    returned values, including displaying the calculated slope and intercept in the command window.

    Submit your internally and externally (i.e. with report(s)) documented source code as a single zip file.