Sign In
Not register? Register Now!
Pages:
6 pages/≈1650 words
Sources:
No Sources
Style:
APA
Subject:
Mathematics & Economics
Type:
Statistics Project
Language:
English (U.S.)
Document:
MS Word
Date:
Total cost:
$ 31.1
Topic:

MAT 243 Project Three Summary Report. Mathematics & Economics. Statistics Project

Statistics Project Instructions:

Project Three: Simple Linear Regression and Multiple Regression
This notebook contains step-by-step directions for Project Three. It is very important to run through the steps in order. Some steps depend on the outputs of earlier steps. Once you have completed the steps in this notebook, be sure to write your summary report.
You are a data analyst for a basketball team and have access to a large set of historical data that you can use to analyze performance patterns. The coach of the team and your management have requested that you come up with regression models that predict the total number of wins for a team in the regular season based on key performance metrics. Although the data set is the same that you used in the previous projects, the data set used here has been aggregated to study the total number of wins in a regular season based on performance metrics shown in the table below. These regression models will help make key decisions to improve the performance of the team. You will use the Python programming language to perform the statistical analyses and then prepare a report of your findings to present for the team’s management. Since the managers are not data analysts, you will need to interpret your findings and describe their practical implications.
There are four important variables in the data set that you will utilize in Project Three.
Variable
What does it represent
total_wins
Total number of wins in a regular season
avg_pts
Average points scored in a regular season
avg_elo_n
Average relative skill of each team in a regular season
avg_pts_differential
Average point differential between the team and their opponents in a regular season
The average relative skill (represented by the variable avg_elo_n in the data set) is simply the average of a team's relative skill in a regular season. Relative skill is measured using the ELO rating. This measure is inferred based on the final score of a game, the game location, and the outcome of the game relative to the probability of that outcome. The higher the number, the higher the relative skill of a team.
Reminder: It may be beneficial to review the summary report document for Project Three prior to starting this Python script. That will give you an idea of the questions you will need to answer with the outputs of this script.
Step 1: Data Preparation
This step uploads the data set from a CSV file and transforms the data into a form that will be used to create regression models. The data will be aggregated to calculate the number of wins for teams in a basketball regular season between the years 1995 and 2015.
Click the block of code below and hit the Run button above.
import numpy as np
import pandas as pd
import scipy.stats as st
import matplotlib.pyplot as plt
from IPython.display import display, HTML
# dataframe for this project
nba_wins_df = pd.read_csv('nba_wins_data.csv')
display(HTML(nba_wins_df.head().to_html()))
print("printed only the first five observations...")
print("Number of rows in the dataset =", len(nba_wins_df))
year_id fran_id avg_pts avg_opp_pts avg_elo_n avg_opp_elo_n avg_pts_differential avg_elo_differential total_wins
0 1995 Bucks 99.341463 103.707317 1368.604789 1497.311587 -4.365854 -128.706798 34
1 1995 Bulls 101.524390 96.695122 1569.892129 1488.199352 4.829268 81.692777 47
2 1995 Cavaliers 90.451220 89.829268 1542.433391 1498.848261 0.621951 43.585130 43
3 1995 Celtics 102.780488 104.658537 1431.307532 1495.936224 -1.878049 -64.628693 35
4 1995 Clippers 96.670732 105.829268 1309.053701 1517.260260 -9.158537 -208.206558 17
printed only the first five observations...
Number of rows in the dataset = 618
Step 2: Scatterplot and Correlation for the Total Number of Wins and Average Points Scored
Your coach expects teams to win more games in a regular season if they have a high average number of points compared to their opponents. This is because the chances of winning are higher if a team scores high in its games. Therefore, it is expected that the total number of wins and the average points scored are correlated. Calculate the Pearson correlation coefficient and its P-value. Make the following edits to the code block below:
Replace ??DATAFRAME_NAME?? with the name of the dataframe used in this project. See Step 1 for the name of dataframe used in this project.
Replace ??POINTS?? with the name of the variable for average points scored in a regular season. See the table included in the Project Three instructions above to pick the variable name. Enclose this variable in single quotes. For example, if the variable name is var1 then replace ??POINTS?? with 'var1'.
Replace ??WINS?? with the name of the variable for the total number of wins in a regular season. Remember to enclose the variable in single quotes. See the table included in the Project Three instructions above to pick the variable name. Enclose this variable in single quotes. For example, if the variable name is var2 then replace ??WINS?? with 'var2'.
The code block below will print a scatterplot of the total number of wins against the average points scored in a regular season.
After you are done with your edits, click the block of code below and hit the Run button above.
import scipy.stats as st
# ---- TODO: make your edits here ----
plt.plot(nba_wins_df['avg_pts'], nba_wins_df['total_wins'], 'o')
plt.title('Total Number of Wins by Average Points Scored', fontsize=20)
plt.xlabel('Average Points Scored')
plt.ylabel('Total Number of Wins')
plt.show()
# ---- TODO: make your edits here ----
correlation_coefficient, p_value = st.pearsonr(nba_wins_df['avg_pts'], nba_wins_df['total_wins'])
print("Correlation between Average Points Scored and the Total Number of Wins ")
print("Pearson Correlation Coefficient =",  round(correlation_coefficient,4))
print("P-value =", round(p_value,4))
Correlation between Average Points Scored and the Total Number of Wins 
Pearson Correlation Coefficient = 0.4777
P-value = 0.0
Step 3: Simple Linear Regression: Predicting the Total Number of Wins using Average Points Scored
The coach of your team suggests a simple linear regression model with the total number of wins as the response variable and the average points scored as the predictor variable. He expects a team to have more wins in a season if it scores a high average points during that season. This regression model will help your coach predict how many games your team might win in a regular season if they maintain a certain average score. Create this simple linear regression model. Make the following edits to the code block below:
Replace ??RESPONSE_VARIABLE?? with the variable name that is being predicted. See the table included in the Project Three instructions above to pick the variable name. Do not enclose this variable in quotes. For example, if the variable name is var1 then replace ??RESPONSE_VARIABLE?? with var1.
Replace ??PREDICTOR_VARIABLE?? with the variable name that is the predictor. See the table included in Project Three instructions above to pick the variable name. Do not enclose this variable in quotes. For example, if the variable name is var2 then replace ??PREDICTOR_VARIABLE?? with var2.
For example, if the variable names are var1 for the response variable and var2 for the predictor variable, then the expression in the code block below should be: model = smf.ols('var1 ~ var2', nba_wins_df).fit()
After you are done with your edits, click the block of code below and hit the Run button above.
import statsmodels.formula.api as smf
# Simple Linear Regression
# ---- TODO: make your edits here ---
model1 = smf.ols('total_wins ~ avg_pts', nba_wins_df).fit()
print(model1.summary())
                            OLS Regression Results                            ==============================================================================
Dep. Variable:             total_wins   R-squared:                       0.228
Model:                            OLS   Adj. R-squared:                  0.227
Method:                 Least Squares   F-statistic:                     182.1
Date:                Wed, 10 Jun 2020   Prob (F-statistic):           1.52e-36
Time:                        22:51:12   Log-Likelihood:                -2385.4
No. Observations:                 618   AIC:                             4775.
Df Residuals:                     616   BIC:                             4784.
Df Model:                           1                                         Covariance Type:            nonrobust                                         ==============================================================================
                 coef    std err          t      P>|t|      [0.025      0.975]
------------------------------------------------------------------------------
Intercept    -85.5476      9.305     -9.194      0.000    -103.820     -67.275
avg_pts        1.2849      0.095     13.495      0.000       1.098       1.472
==============================================================================
Omnibus:                       24.401   Durbin-Watson:                   1.768
Prob(Omnibus):                  0.000   Jarque-Bera (JB):               11.089
Skew:                          -0.033   Prob(JB):                      0.00391
Kurtosis:                       2.347   Cond. No.                     1.97e+03
==============================================================================
Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
[2] The condition number is large, 1.97e+03. This might indicate that there arestrong multicollinearity or other numerical problems.
Step 4: Scatterplot and Correlation for the Total Number of Wins and Average Relative Skill
Your management expects the team to win more games in the regular season if it maintains a high average relative skill compared to other teams. Therefore, it is expected that the total number of wins and the average relative skill are correlated. Calculate the Pearson correlation coefficient and its P-value. Make the following edits to the code block below:
Replace ??DATAFRAME_NAME?? with the name of the dataframe used in this project. See Step 1 for the name of dataframe used in this project.
Replace ??RELATIVE_SKILL?? with the name of the variable for average relative skill in a regular season. See the table included in the Project Three instructions above to pick the variable name. Enclose this variable in single quotes. For example, if the variable name is var2 then replace ??RELATIVE_SKILL?? with 'var2'.
Replace ??WINS?? with the name of the variable for total number of wins in a regular season. See the table included in Project Three instructions above to pick the variable name. Enclose this variable in single quotes. For example, if the variable name is var3 then replace ??WINS?? with 'var3'.
The code block below will print a scatterplot of the total number of wins against the average relative skill in a regular season.
After you are done with your edits, click the block of code below and hit the Run button above.
# ---- TODO: make your edits here ---
plt.plot(nba_wins_df['avg_elo_n'], nba_wins_df['total_wins'], 'o')
plt.title('Wins by Average Relative Skill', fontsize=20)
plt.xlabel('Average Relative Skill')
plt.ylabel('Total Number of Wins')
plt.show()
# ---- TODO: make your edits here ---correlation_coefficient, p_value = st.pearsonr(nba_wins_df['avg_elo_n'], nba_wins_df['total_wins'])
print("Correlation between Average Relative Skill and Total Number of Wins ")
print("Pearson Correlation Coefficient =",  round(correlation_coefficient,4))
print("P-value =", round(p_value,4))
Correlation between Average Relative Skill and Total Number of Wins 
Pearson Correlation Coefficient = 0.9072
P-value = 0.0
Step 5: Multiple Regression: Predicting the Total Number of Wins using Average Points Scored and Average Relative Skill
Instead of presenting a simple linear regression model to the coach, you can suggest a multiple regression model with the total number of wins as the response variable and the average points scored and the average relative skill as predictor variables. This regression model will help your coach predict how many games your team might win in a regular season based on metrics like the average points scored and average relative skill. This model is more practical because you expect more than one performance metric to determine the total number of wins in a regular season. Create this multiple regression model. Make the following edits to the code block below:
Replace ??RESPONSE_VARIABLE?? with the variable name that is being predicted. See the table included in the Project Three instructions above. Do not enclose this variable in quotes. For example, if the variable name is var0 then replace ??RESPONSE_VARIABLE?? with var0.
Replace ??PREDICTOR_VARIABLE_1?? with the variable name for average points scored. Hint: See the table included in the Project Three instructions above. Do not enclose this variable in quotes. For example, if the variable name is var1 then replace ??PREDICTOR_VARIABLE_1?? with var1.
Replace ??PREDICTOR_VARIABLE_2?? with the variable name for average relative skill. Hint: See the table included in the Project Three instructions above. Do not enclose this variable in quotes. For example, if the variable name is var2 then replace ??PREDICTOR_VARIABLE_2?? with var2.
For example, if the variable names are var0 for the response variable and var1, var2 for the predictor variables, then the expression in the code block below should be: model = smf.ols('var0 ~ var1 + var2', nba_wins_df).fit()
After you are done with your edits, click the block of code below and hit the Run button above.
import statsmodels.formula.api as smf
# Multiple Regression
# ---- TODO: make your edits here ---model2 = smf.ols('total_wins ~ avg_pts + avg_elo_n', nba_wins_df).fit()
print(model2.summary())
                            OLS Regression Results                            ==============================================================================
Dep. Variable:             total_wins   R-squared:                       0.837
Model:                            OLS   Adj. R-squared:                  0.837
Method:                 Least Squares   F-statistic:                     1580.
Date:                Wed, 10 Jun 2020   Prob (F-statistic):          4.41e-243
Time:                        22:56:38   Log-Likelihood:                -1904.6
No. Observations:                 618   AIC:                             3815.
Df Residuals:                     615   BIC:                             3829.
Df Model:                           2                                        Covariance Type:            nonrobust           
                              ==============================================================================                 coef    std err          t      P>|t|      [0.025      0.975]
------------------------------------------------------------------------------Intercept   -152.5736      4.500    -33.903      0.000    -161.411    -143.736
avg_pts        0.3497      0.048      7.297      0.000       0.256       0.444
avg_elo_n      0.1055      0.002     47.952      0.000       0.101       0.110
==============================================================================Omnibus:                       89.087   Durbin-Watson:                   1.203
Prob(Omnibus):                  0.000   Jarque-Bera (JB):              160.540
Skew:                          -0.869   Prob(JB):                     1.38e-35
Kurtosis:                       4.793   Cond. No.                     3.19e+04
==============================================================================
Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
[2] The condition number is large, 3.19e+04. This might indicate that there are
strong multicollinearity or other numerical problems.
Step 6: Multiple Regression: Predicting the Total Number of Wins using Average Points Scored, Average Relative Skill, and Average Points DifferentialThe coach also wants you to consider the average points differential as a predictor variable in the multiple regression model. Create a multiple regression model with the total number of wins as the response variable, and average points scored, average relative skill, and average points differential as predictor variables. This regression model will help your coach predict how many games your team might win in a regular season based on metrics like the average score, average relative skill, and the average points differential between the team and their opponents.
You are to write this code block yourself.
Use Step 5 to help you write this code block. Here is some information that will help you write this code block. Reach out to your instructor if you need help.
The dataframe used in this project is called nba_wins_df.The variable **avg_pts** represents average points scored by each team in a regular season.The variable **avg_elo_n** represents average relative skill of each team in a regular season.The variable **avg_pts_differential** represents average points differential between each team and their opponents in a regular season.Print the model summary.Write your code in the code block section below. After you are done, click this block of code and hit the Run button above. Reach out to your instructor if you need more help with this step.
# Write your code in this code block sectionmodel3 = smf.ols('total_wins ~ avg_pts + avg_elo_n + avg_pts_differential', nba_wins_df).fit()
print(model3.summary())                            OLS Regression Results                            ==============================================================================
Dep. Variable:             total_wins   R-squared:                       0.876
Model:                            OLS   Adj. R-squared:                  0.876
Method:                 Least Squares   F-statistic:                     1449.
Date:                Wed, 10 Jun 2020   Prob (F-statistic):          5.03e-278
Time:                        23:07:12   Log-Likelihood:                -1819.8
No. Observations:                 618   AIC:                             3648.
Df Residuals:                     614   BIC:                             3665.
Df Model:                           3                                         Covariance Type:            nonrobust                                         ========================================================================================                           coef    std err          t      P>|t|      [0.025      0.975]
----------------------------------------------------------------------------------------Intercept              -35.8921      9.252     -3.879      0.000     -54.062     -17.723
avg_pts                  0.2406      0.043      5.657      0.000       0.157       0.324
avg_elo_n                0.0348      0.005      6.421      0.000       0.024       0.045
avg_pts_differential     1.7621      0.127     13.928      0.000       1.514       2.011
==============================================================================Omnibus:                      181.805   Durbin-Watson:                   0.975
Prob(Omnibus):                  0.000   Jarque-Bera (JB):              506.551
Skew:                          -1.452   Prob(JB):                    1.01e-110
Kurtosis:                       6.352   Cond. No.                     7.51e+04
==============================================================================
Warnings:[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.[2] The condition number is large, 7.51e+04. This might indicate that there arestrong multicollinearity or other numerical problems.End of Project ThreeDownload the HTML output and submit it with your summary report for Project Three. The HTML output can be downloaded by clicking File, then Download as, then HTML. Do not include the Python code within your summary report.

Statistics Project Sample Content Preview:

MAT 243 Project Three Summary Report
[Full Name]
[SNHU Email]
Southern New Hampshire University
1. Introduction
The analyses in this project aim to use aggregated data describing team performance to predict the total number of wins for a team in the regular season. This project will use regression models and various performance metrics to form predictions that will help make decisions to improve the team's performance.
2. Data Preparation
A team's avg_pts_differential is the average difference between the team's score and their opponent's score in a regular season. This generally describes the difference between the team's score and their opponent's score in a typical regular-season game.
A team's avg_elo_n is the average relative skill of a team in a regular season. This describes the team's general relative skill level throughout a regular season, with a higher number represented a higher relative skill level.
3. Scatterplot and Correlation for the Total Number of Wins and Average Points Scored
In general, data visualization techniques, such as scatterplot creation, are used to see if there is a general correlation between two variables, and to see the nature of the correlation, if it exists. The existence of a correlation between two variables may be indicated by a scatterplot that visibly gathers around a certain curve, while the degree or direction of the correlation is seen in how densely the scatterplot gathers around a certain curve. Finally, the direction of the correlation is seen in the direction or slope of the curve around which the scatterplot gathers.
Meanwhile, the strength of a correlation between two variables is described by the magnitude or absolute value of the correlation coefficient, and the direction of the correlation is described by the sign of the correlation coefficient.
In this case, the scatterplot shows us data points that generally gather around a curve with a positive slope. This tells us that the total number of wins and the average points scored have a moderate positive correlation. This statement is supported by the Pearson Correlation Coefficient between the total number of wins and the average points scored, which is 0.47777. Because the P-value is 0.0, we conclude that the correlation is statistically significant.
4. Simple Linear Regression: Predicting the Total Number of Wins using Average Points Scored
Table 1: Hypothesis Test for the Overall F-Test
Statistic

Value

Test Statistic

182.1

P-value

0.0000

In general, simple linear regression is used to find the equation of a line that represents the correlation between two variables (i.e. the line around which the scatterplot gathers). This line is then used to predict the value of one variable (the response variable), given the value of the other variable (the predictor variable).
In this case, linear regression gives us the following equation:
Total Number of Wins = (1.2849 x Average Points Scored) - 85.5476
The null hypothesis of the overall F-test denoted H0, states that the fit of the regression model with no predictors is the same as the fit of a specified regression model, while the alternative hypothesis, denoted HA, states that the specified...
Updated on
Get the Whole Paper!
Not exactly what you need?
Do you need a custom essay? Order right now:

You Might Also Like Other Topics Related to basketball:

HIRE A WRITER FROM $11.95 / PAGE
ORDER WITH 15% DISCOUNT!