Login
📚 Python for Introductory Statistics: Lab Workbook
Chapters ▾

14.5 Regression

Multiple Linear Regression

Watch demo video

Lab 14.5.1

The dataset in the website (URL below) includes 20 columns about home sale, including price, number of bedrooms and bathrooms, areas etc. The data includes 21,613 entries.

  1. Write a Python code to find the least-squares prediction equation, y=β0+β1x1+β2x2+β3x3+ϵ for these data where, y is price, x1 is bedrooms, x2 sqft_basement and x3 is sqft_living.
  2. Use the overall F test to determine whether the model contributes significant information to the prediction of y with 1% level of significance.
  3. What is the value of R-squared. That is, the coefficient of determination.
  4. Does the sqft_living, x3, contribute significant information for the prediction of the price, y, given that x1 and x2 are already in the model? (use α=0.05)

kc_house_data.csv

view answer

Logistic Regression

Lab 14.5.2

The data set below (URL) contains the occurrence of coronary heart disease, chd, tobacco, obesity, age, alcohol, etc. For chd, 0 means patient has no chd and 1 means patient has chd.

  1. Write a Python code to read the data set and display the first five rows.
  2. Write a Python code to fit a logistic regression model where the dependent variable is chd and the predictor variables are ldl, sbs and age. Use 5% level of significance.

heart.csv

view answer

Adapted from Python for Introductory Statistics: Student's Lab Workbook, by Simon Aman (Truman College, City Colleges of Chicago), licensed under CC BY 4.0. Changes were made: reformatted as an accessible XYZ web edition with live in-browser code cells. License: CC-BY-4.0.