Ask Applied Statistics Expert

Final Project

Instructions:

In this project, you will write two object classes and a helper function to read in text data.

Three Python files have been provided for you to complete:

  • data.py
  • linear_regression.py
  • read_data.py

You will need to edit these files and push them to your ncsu repo:

  • You may work together, but you must list all collaborators in your read_data.py file.
  • Please no copy and pasting among collaborators. You'll learn better if you discuss and write your code on your own.
  • If you use, online or other resources, also list them in your read_data.py file.

Part I: Reading data into two lists. Edit the file read_data.py

1. In the file read_data.py, define a function read_data that takes in a string called input_file_name that contains a path to an input file. Assume that the input file path contains two floating point number per line separated by spaces. Your function should return two lists whose elements are those floating point numbers contained in the input file.

Part II: Data class and methods. Edit the file data.py

2. Write a Data class with an __init__ method that takes two lists of numbers as parameters and stores them in two attributes x and y.

3. Write a Data method called num_obs that takes in no parameters and outputs the number of observations in the data, i.e. the length of its attribute x (or y since they should be the same.).

4. Write a __str__ method that returns a string that gives the following format when printed.

>>> dat = Data([1,2,3],[2,4,6])

>>> print(dat)

x              y

1              2

2              4

3              6

5. Write a Data method called compute_sample_means that returns sample mean of the attributes x and sample mean of the attributes y, as a tuple of numbers.

6. Write a Data method called compute_least_squares_fit that returns the intercept and slope of the simple linear regression ?t of the data.

Hint: First compute the quantities Sxy and Sxx. Then compute the slope β1 and then finally compute the intercept β0.

7. Write a Data method called compute_SST that returns the sum of squares total (SST) of the attribute y.

Part III: SLR class and methods. Edit the file linear_regression.py

8. Write the SLR class with an __init__ method that takes in a Data object as a parameter. The __init__ method should store the contents of the parameter in an attribute called data. It should also compute the intercept β0 and slope β1 and store theses values in the attributes beta0 and beta1, respectively.

9. Write the SLR method predict that takes a new x_new value as a parameter and predicts a new y_new value.

10. Write the SLR method compute_residuals that returns the residuals of the SLR object in a list of numbers.

11. Write the SLR method compute_SSResid that returns the sum of square residuals (SSResid).

12. Write the SLR method compute_residual_sd that returns the residual standard deviation.

13. Write the SLR method compute_rsquared that returns the R-squared of the SLR fit.

14. Write a __str__ method that returns a string that gives the following format when printed (Note the number of decimal digits!).

>>> filename = 'bmi_vs_sbp.txt'

>>> x, y = read_data(filename)

>>> dat = Data(x,y)

>>> lm = SLR(dat)

>>> print(lm)

Least squares fit on 10 data points.

Intercept = 45.584331

Slope = 3.465523

Residual standard deviation = 13.051139

R-squared = 0.731364

Attachment:- Assignment Files.rar

Applied Statistics, Statistics

  • Category:- Applied Statistics
  • Reference No.:- M92554099

Have any Question?


Related Questions in Applied Statistics

Question onea a factory manager claims that workers at

QUESTION ONE (a) A factory manager claims that workers at plant A are faster than those at plant B. To test the claim, a random sample of times (in minutes) taken to complete a given task was taken from each of the plant ...

You are expected to work in groups and write a research

You are expected to work in groups and write a research report. When you work on your report, you need to use the dataset, and other sources such as journal articles. If you use website material, please pay attention to ...

Assignment -for each of the prompts below report the

Assignment - For each of the prompts below, report the appropriate degrees of freedom, t statistic, p-value and plot using the statistical software platform of your choice (R/STATA) 1) A sample of 12 men and 14 women hav ...

Assignment - research topicpurpose the purpose of this task

Assignment - Research topic Purpose: The purpose of this task is to ensure you are progressing satisfactorily with your research project, and that you have clean, useable data to analyse for your final project report. Ta ...

Assessment task -you become interested in the non-skeletal

Assessment Task - You become interested in the non-skeletal effects of vitamin D and review the literature. On the basis of your reading you find that there is some evidence to suggest that vitamin D deficiency is linked ...

Part a -question 1 - an analyst considers to test the order

PART A - Question 1 - An analyst considers to test the order of integration of some time series data. She decides to use the DF test. She estimates a regression of the form Δy t = μ + ψy t-1 + u t and obtains the estimat ...

Medical and applied physiology experimental report

Medical and Applied Physiology Experimental Report Assignment - Title - Compare the working and spatial memory by EEG. 30 students were tested (2 memory games were played to test their memory - a card game and a number g ...

Business data analysis computer assignment -part 1

Business Data Analysis Computer Assignment - PART 1 - Economists believe that high rates of unemployment are linked to decreased life satisfaction ratings. To investigate this relationship, a researcher plans to survey a ...

Question - go to the website national quality forum nqf

Question - Go to the website, National Quality Forum (NQF), located in the Webliography, and download the article by WIRED FOR QUALITY: The Intersection of Health IT and Healthcare Quality, Number 8, MARCH 2008. You are ...

Go to the webliography source for the national cancer

Go to the Webliography source for the National Cancer Institute's Surveillance, Epidemiology, and End Results (SEER) Program. In the Fast Stats, create your own cancer statistical report, "Stratified by Data Type," and u ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As