Question

In: Math

5.232608753 51.33997 1 4.559347708 3.047033 0 4.550088246 11.71957 1 3.386566659 28.04548 1 0.989064618 0.202602 0 4.555668273...

  1. 5.232608753 51.33997 1
    4.559347708 3.047033 0
    4.550088246 11.71957 1
    3.386566659 28.04548 1
    0.989064618 0.202602 0
    4.555668273 67.83218 1
    4.186405129 53.06328 1
    1.207150769 78.43352 0
    3.445792543 14.46725 1
    2.962975266 23.10411 0
    0.173612404 65.70817 0
    2.768815371 65.28198 1
    2.747367434 97.82201 1
    4.486882933 77.4523 1
    4.824678695 0.743551 0
    5.586206724 48.65186 1
    2.755386381 73.45392 1
    1.787901977 97.36504 1
    5.951385802 90.85691 1
    2.737556923 15.44293 0
    5.408894983 4.157112 0
    1.715859824 0.937882 0
    1.278844906 74.59771 0
    2.514277044 97.32341 1
    3.187058008 38.67714 1
    4.949777159 87.91089 1
    5.948802076 99.45704 1
    4.58854855 73.22006 1
    4.944593251 2.002865 0
    4.095092929 30.82503 1
    1.580255616 81.42979 1
    5.582168688 77.37155 1
    1.409875297 73.8556 1
    4.173571574 10.78412 0
    3.405384527 76.08957 1
    5.303746588 91.13028 1
    2.646338619 30.76739 0
    5.648448558 24.47563 0
    5.460162608 6.448907 1
    2.530400279 92.75311 1
    5.282410782 26.05696 1
    4.798709185 42.12116 1
    4.300055705 57.20119 1
    4.729502404 6.523547 0
    2.476612604 55.6309 1
    3.190133005 67.05927 1
    1.021463153 77.07357 1
    0.733750098 95.86227 1
    2.724156232 4.533329 0
    4.232730005 96.12467 1
    For a column of data x and a column of data y, there is an equation that relates the slope of the line of best fit (m) with the correlation coefficient (r). That equation is:

m = r * std(y)/std(x)

In the equation above, std(y) represents the standard deviation of the y column of data and std(x) is the standard deviation of the x column of data.

Use the Pandas .corr() and .std() methods to compute the slope of the line of best fit between Diameter and Pigment(first & second col).

Next, use compute the y-intecept of the line of best fit using:

b = ybar – m*xbar

         Lastly, plot the line of best fit using matplotlib.pyplot.

Solutions

Expert Solution

Assuming the data is already stored in data.csv by the column names of x and y

Code

#importing pandas as pd

import pandas as pd

#importing matplotlib,pyplot as plt

import matplotlib.pyplot as plt

from matplotlib import pylab

#making data frame from the csv file

df = pd.read_csv("data.csv)

#calculating the correlation

r = df.corr(method = 'pearson')

#calculating the standard deviation of all the variables in the dataset where axis = 0 calculation #column wise correlation and axis = 1 calculation row wise

sr = df.std(axis = 0, skipna = True)

#calculating the standard deviation of the specific column

stdy = df.loc[:,"y"].std()

stdx = df.loc[:,"x"].std()

m = r*stdy/stdx

#calculating mean of the y values

ybar = df.loc[:,"y"].mean()

xbar = df.loc[:,"x"].mean()

b = ybar – m*xbar

Y_pred = m*x + b

fig = plt.figure()
ax = plt.axes()

ax.plot(x, Y_pred,linestyle = '-')

plot.show()

Output

r = -0.18959

std(y) = 33.68728

std(x) = 1.55705

m = -0.18959*33.68728 / 1.55705= -4.1019

ybar = average of y values = 51.32871

xbar = average of x values = 3.54132

b = ybar – m*xbar = 51.32871 - (-4.1019)*3.54132 = 65.85485


Related Solutions

3. In R4 , does the set {(1, 1, 1, 0,(1, 0, 0, 0),(0, 1, 0,...
3. In R4 , does the set {(1, 1, 1, 0,(1, 0, 0, 0),(0, 1, 0, 0),(0, 0, 1, 1)}, span R4? In other words, can you write down any vector (a, b, c, d) ∈ R4 as a linear combination of vectors in the given set ? Is the above set of vectors linearly independent ? 4. In the vector space P2 of polynomials of degree ≤ 2, find explicitly a polynomial p(x) which is not in the span...
0. 0. 0. 0.0. 0. 0. 0. 0. 1. 1. 1. 1. 1. 1. 2. 2. 2. 3. 4.
0. 0. 0. 0.0. 0. 0. 0. 0.   1. 1. 1. 1. 1. 1. 2. 2. 2. 3.   4. A.)MEAN – B.)MEDIAN - C.)MODE - D.)STANDARD DEVIATION – E.)5 NUMBER SUMMARY – F.)BOX AND WHISKERS PLOT – G.) OUTLIERS-
0. 0. 0. 0.0. 0. 0. 0. 0. 1. 1. 1. 1. 1. 1. 2. 2. 2. 3. 4.
0. 0. 0. 0.0. 0. 0. 0. 0.   1. 1. 1. 1. 1. 1. 2. 2. 2. 3.   4. A.)5 NUMBER SUMMARY – B.)BOX AND WHISKERS PLOT – C.) OUTLIERS-
0 0 2 0 5 3 1 12 0 0 0 1 6 0 1 1...
0 0 2 0 5 3 1 12 0 0 0 1 6 0 1 1 2 8 1 3 1 6 2 4 0 16 17 0 8 0 3 0 0 1 2 5 2 0 2 1 5 0 7 0 1 0 0 1 0 0 3 1 9 4 1 3 0 1 1 1 0 7 1 9 2 0 1 1 1 1 7 2 7 1 2 =============================== (a) What type of...
A = ⌈ 1 2 0 ⌉ | -1 0 1 | ⌊ 0 1 -1...
A = ⌈ 1 2 0 ⌉ | -1 0 1 | ⌊ 0 1 -1 ⌋ and B = ⌈ 1/3 -2/3 -2/3 ⌉ | 1/3 1/3 1/3 | ⌊ 1/3 1/3 -2/3 ⌋ Given matrices A and B, find AB and BA. Show all work. Are they equal, and why or why not?
Let A =   [  0 2 0 1 0 2 0 1 0 ]  . (a)...
Let A =   [  0 2 0 1 0 2 0 1 0 ]  . (a) Find the eigenvalues of A and bases of the corresponding eigenspaces. (b) Which of the eigenspaces is a line through the origin? Write down two vectors parallel to this line. (c) Find a plane W ⊂ R 3 such that for any w ∈ W one has Aw ∈ W , or explain why such a plain does not exist. (d) Write down explicitly...
Let A = 0 2 0 1 0 2 0 1 0 . (a) Find the...
Let A = 0 2 0 1 0 2 0 1 0 . (a) Find the eigenvalues of A and bases of the corresponding eigenspaces. (b) Which of the eigenspaces is a line through the origin? Write down two vectors parallel to this line. (c) Find a plane W ⊂ R 3 such that for any w ∈ W one has Aw ∈ W , or explain why such a plain does not exist. (d) Write down explicitly a diagonalizing...
Let A = 0 2 0 1 0 2 0 1 0 . (a) Find the...
Let A = 0 2 0 1 0 2 0 1 0 . (a) Find the eigenvalues of A and bases of the corresponding eigenspaces. (b) Which of the eigenspaces is a line through the origin? Write down two vectors parallel to this line. (c) Find a plane W ⊂ R 3 such that for any w ∈ W one has Aw ∈ W , or explain why such a plain does not exist. (d) Write down explicitly a diagonalizing...
Matrix: Ax b [2 1 0 0 0 | 100] [1 1 -1 0 -1 |...
Matrix: Ax b [2 1 0 0 0 | 100] [1 1 -1 0 -1 | 0] [-1 0 1 0 1 | 50] [0 -1 0 1 1 | 120] [0 1 1 -1 1 | 0] Problem 5 Compute the solution to the original system of equations by transforming y into x, i.e., compute x = inv(U)y. Solution: %code I have not Idea how to do this. Please HELP!
y''-2y'+1=0; y(0)=0, y'(0)=-1
y''-2y'+1=0; y(0)=0, y'(0)=-1
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT