0% found this document useful (0 votes)
6 views6 pages

GDP GCF Inflation

The document presents an analysis of GDP, Gross Capital Formation (GCF), and inflation data from 2014 to 2023 using Python's statsmodels library. It includes the creation of a correlation matrix, two regression analyses (GDP as a function of GCF and inflation as a function of GCF), and visualizations of the relationships. The results indicate a strong correlation between GDP and GCF, while the relationship between inflation and GCF is weaker.

Uploaded by

dmarker331
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views6 pages

GDP GCF Inflation

The document presents an analysis of GDP, Gross Capital Formation (GCF), and inflation data from 2014 to 2023 using Python's statsmodels library. It includes the creation of a correlation matrix, two regression analyses (GDP as a function of GCF and inflation as a function of GCF), and visualizations of the relationships. The results indicate a strong correlation between GDP and GCF, while the relationship between inflation and GCF is weaker.

Uploaded by

dmarker331
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

gdp-gcf-inflation

April 16, 2025

[3]: !pip install statsmodels


import pandas as pd
import numpy as np
import statsmodels.api as sm
import matplotlib.pyplot as plt
import seaborn as sns

# Create the dataframe from the provided data


data = {
'Year': ['2014-15', '2015-16', '2016-17', '2017-18', '2018-19', '2019-20',␣
↪'2020-21', '2021-22', '2022-23'],

'GDP': [10527674, 11369493, 12308193, 13144582, 13992914, 14534641,␣


↪13694869, 15021846, 16071429],

'GCF': [4179779, 4422659, 4918077, 5791573, 6396053, 6106406, 5597593,␣


↪7648091, 8677533],

'Inflation': [-3.35, -1.76, 0.04, -1.62, 0.61, -0.21, 2.89, -1.49, 1.57]
}

df = pd.DataFrame(data)

# Convert GCF and GDP to millions for better coefficient interpretation


df['GDP_millions'] = df['GDP'] / 1000000
df['GCF_millions'] = df['GCF'] / 1000000

# Correlation matrix
print("Correlation Matrix:")
corr_matrix = df[['GDP_millions', 'GCF_millions', 'Inflation']].corr()
print(corr_matrix)

# Visualize the correlation matrix


plt.figure(figsize=(8, 6))
sns.heatmap(corr_matrix, annot=True, cmap='coolwarm', center=0)
plt.title('Correlation Matrix')
plt.show()

# Regression 1: GDP as dependent variable, GCF as independent variable


print("\nRegression 1: GDP ~ GCF")

1
X_gdp = sm.add_constant(df['GCF_millions']) # Adds a constant term to the␣
↪predictor

y_gdp = df['GDP_millions']

model_gdp = sm.OLS(y_gdp, X_gdp)


results_gdp = model_gdp.fit()
print(results_gdp.summary())

# Regression 2: Inflation as dependent variable, GCF as independent variable


print("\nRegression 2: Inflation ~ GCF")
X_inf = sm.add_constant(df['GCF_millions'])
y_inf = df['Inflation']

model_inf = sm.OLS(y_inf, X_inf)


results_inf = model_inf.fit()
print(results_inf.summary())

# Plotting the relationships


fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(14, 6))

# GDP vs GCF
ax1.scatter(df['GCF_millions'], df['GDP_millions'])
ax1.plot(df['GCF_millions'], results_gdp.fittedvalues, color='red')
ax1.set_xlabel('Gross Capital Formation (millions)')
ax1.set_ylabel('GDP (millions)')
ax1.set_title('GDP vs GCF')

# Inflation vs GCF
ax2.scatter(df['GCF_millions'], df['Inflation'])
ax2.plot(df['GCF_millions'], results_inf.fittedvalues, color='red')
ax2.set_xlabel('Gross Capital Formation (millions)')
ax2.set_ylabel('Inflation (%)')
ax2.set_title('Inflation vs GCF')

plt.tight_layout()
plt.show()

Collecting statsmodels
Downloading statsmodels-0.14.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014
_x86_64.whl.metadata (9.2 kB)
Requirement already satisfied: numpy<3,>=1.22.3 in
/usr/local/lib/python3.11/dist-packages (from statsmodels) (2.0.2)
Requirement already satisfied: scipy!=1.9.2,>=1.8 in
/usr/local/lib/python3.11/dist-packages (from statsmodels) (1.14.1)
Requirement already satisfied: pandas!=2.1.0,>=1.4 in
/usr/local/lib/python3.11/dist-packages (from statsmodels) (2.2.2)
Collecting patsy>=0.5.6 (from statsmodels)

2
Downloading patsy-1.0.1-py2.py3-none-any.whl.metadata (3.3 kB)
Requirement already satisfied: packaging>=21.3 in
/usr/local/lib/python3.11/dist-packages (from statsmodels) (24.2)
Requirement already satisfied: python-dateutil>=2.8.2 in
/usr/local/lib/python3.11/dist-packages (from pandas!=2.1.0,>=1.4->statsmodels)
(2.9.0.post0)
Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.11/dist-
packages (from pandas!=2.1.0,>=1.4->statsmodels) (2025.2)
Requirement already satisfied: tzdata>=2022.7 in /usr/local/lib/python3.11/dist-
packages (from pandas!=2.1.0,>=1.4->statsmodels) (2025.2)
Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.11/dist-
packages (from python-dateutil>=2.8.2->pandas!=2.1.0,>=1.4->statsmodels)
(1.17.0)
Downloading
statsmodels-0.14.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
(10.8 MB)
���������������������������������������� 10.8/10.8 MB
46.2 MB/s eta 0:00:00
Downloading patsy-1.0.1-py2.py3-none-any.whl (232 kB)
���������������������������������������� 232.9/232.9 kB
18.1 MB/s eta 0:00:00
Installing collected packages: patsy, statsmodels
Successfully installed patsy-1.0.1 statsmodels-0.14.4
Correlation Matrix:
GDP_millions GCF_millions Inflation
GDP_millions 1.000000 0.948508 0.603680
GCF_millions 0.948508 1.000000 0.440572
Inflation 0.603680 0.440572 1.000000

3
Regression 1: GDP ~ GCF
OLS Regression Results
==============================================================================
Dep. Variable: GDP_millions R-squared: 0.900
Model: OLS Adj. R-squared: 0.885
Method: Least Squares F-statistic: 62.77
Date: Wed, 16 Apr 2025 Prob (F-statistic): 9.70e-05
Time: 18:05:22 Log-Likelihood: -7.0432
No. Observations: 9 AIC: 18.09
Df Residuals: 7 BIC: 18.48
Df Model: 1
Covariance Type: nonrobust
================================================================================
coef std err t P>|t| [0.025 0.975]
--------------------------------------------------------------------------------
const 6.5673 0.886 7.410 0.000 4.472 8.663
GCF_millions 1.1456 0.145 7.923 0.000 0.804 1.487

4
==============================================================================
Omnibus: 0.604 Durbin-Watson: 0.951
Prob(Omnibus): 0.740 Jarque-Bera (JB): 0.440
Skew: 0.441 Prob(JB): 0.803
Kurtosis: 2.372 Cond. No. 27.8
==============================================================================

Notes:
[1] Standard Errors assume that the covariance matrix of the errors is correctly
specified.

Regression 2: Inflation ~ GCF


OLS Regression Results
==============================================================================
Dep. Variable: Inflation R-squared: 0.194
Model: OLS Adj. R-squared: 0.079
Method: Least Squares F-statistic: 1.686
Date: Wed, 16 Apr 2025 Prob (F-statistic): 0.235
Time: 18:05:22 Log-Likelihood: -17.092
No. Observations: 9 AIC: 38.18
Df Residuals: 7 BIC: 38.58
Df Model: 1
Covariance Type: nonrobust
================================================================================
coef std err t P>|t| [0.025 0.975]
--------------------------------------------------------------------------------
const -3.7926 2.707 -1.401 0.204 -10.193 2.608
GCF_millions 0.5734 0.442 1.298 0.235 -0.471 1.618
==============================================================================
Omnibus: 2.102 Durbin-Watson: 2.616
Prob(Omnibus): 0.350 Jarque-Bera (JB): 0.662
Skew: 0.664 Prob(JB): 0.718
Kurtosis: 2.964 Cond. No. 27.8
==============================================================================

Notes:
[1] Standard Errors assume that the covariance matrix of the errors is correctly
specified.
/usr/local/lib/python3.11/dist-packages/scipy/stats/_axis_nan_policy.py:418:
UserWarning: `kurtosistest` p-value may be inaccurate with fewer than 20
observations; only n=9 observations were given.
return hypotest_fun_in(*args, **kwds)
/usr/local/lib/python3.11/dist-packages/scipy/stats/_axis_nan_policy.py:418:
UserWarning: `kurtosistest` p-value may be inaccurate with fewer than 20
observations; only n=9 observations were given.
return hypotest_fun_in(*args, **kwds)

5
[ ]:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy