Association Between Electric Consumption and Co2 Emission

 

Introduction

In gapminder data, the association between electric consumption and Co2 Emission was trying to find out.

Getting and Preparing Data



Data Analysis




The p-value is lower than 0.05 so we reject the null hypthothesis that there is definetly an association between electric consumption and Co2 Emission.

R-squared value is %3, which is pretty low . The low value indicates that we might find other explanatory variables to make our model stronger.

Basic Linear Regression Model

The regression function with their coefficients are "Co2 Emission = 3.482e+6 relectrciperperson + 1.58e+06"




Codes

import numpy
import pandas as pandas
import statsmodels.api
import statsmodels.formula.api as smf

import matplotlib.pyplot as plt
from sklearn.preprocessing import Normalizer

import seaborn

# bug fix for display formats to avoid run time errors
pandas.set_option('display.float_format', lambda x:'%.2f'%x)

#call in data set
data = pandas.read_csv('data/gapminder.csv')

# convert variables to numeric format using convert_objects function
data['co2emissions'] = pandas.to_numeric(data['co2emissions'], errors='coerce')
data['relectricperperson'] = pandas.to_numeric(data['relectricperperson'], errors='coerce')


############################################################################################
# BASIC LINEAR REGRESSION
############################################################################################
scat1 = seaborn.regplot(x="relectricperperson", y="co2emissions", scatter=True, data=data)
plt.xlabel('Electric Usage per Person')
plt.ylabel('Co2 Emission')
plt.title ('Scatterplot for the Association Electric Usage per Person and Co2 Emission')
print(scat1)

print ("OLS regression model for the association between electric usage per person and Co2 Emission")
reg1 = smf.ols('co2emissions ~ relectricperperson', data=data).fit()
print (reg1.summary())

Comments

Popular posts from this blog

Logistic Regresion in Nicotine Dependence and Alcohol Dependence

Lasso Regression in Income per Person

CO2 Emissions Corelations