Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The code shouldnt use if-else loops. You just have to create a function with a b r variables and map each variable to the specific

The code shouldnt use if-else loops. You just have to create a function with a b r variables and map each variable to the specific equations. And then you have index ur table in a certain way where you can input the data into the equation Write a function (using the function keyword) that:

  • Accepts two vectors (x) and (y) as input. We will later call this function with x representing height and y representing weight.
  • Calculates the the slope (b) and intercept (a) of the regression line (i.e., the best fitting line through the points defined by x, y coordinates) according to equations below
  • Calculates the correlation coefficient (r) for the two variables according to equation below. Do not use the built-in Matlab function for correlation (but note that you could check your code by comparing your results with Matlab's correlation function)
  • Returns the values of a,b, and r to the main program
  • Complete the calculations with matrix algebra -- not loops.
  • Take special care to use element-wise operations (e.g. .* and .^)

For a regression line, we have:

y = a + b * x

Where the slope (b), intercept (a) of the regression line can be calculated as:

Note that n represents the number of observations and the capital sigma represents summation (if you have never seen this notation, read this wiki page (Links to an external site.)).https://en.wikipedia.org/wiki/Summation

The correlation coefficient (r) can be calculated as follows:

To reduce error in converting these equations to Matlab, try to avoid having one long equation on one line. It helps to break the equations (especially the equation for r) into smaller equations and save these to temporary variables. Hint: many of the calculations in these formulas imply "element-by-element" multiplication or raising each individual element of a vector to some power. There is specific Matlab notation you have to use to force the element-by-element computation

Paste the code for your function below.

GIVE ME a,b and r value.

Within the main program:

  • Use the estimates of b and a to generate a regression line
  • Plot the regression line on a 2-dimensional graph (remember that x is height, y is weight)
  • Add the original data to the graph as points
  • Label the x and y axis

Paste the code for your main program below (not the resulting image). You are not allowed to use "lsline"

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Access Patterns Database Interactions In Object Oriented Applications

Authors: Clifton Nock

1st Edition

0321555627, 978-0321555625

More Books

Students also viewed these Databases questions