Python para enfermeiras (21)¶
Statsmodel: pacote Python de estatística¶
In [1]:
# Para visualização de gráficos
from pylab import *
%matplotlib inline
In [11]:
import numpy as np
import pandas as pd
import statsmodels as st
import sys
import warnings
if not sys.warnoptions:
warnings.simplefilter("ignore")
warnings.simplefilter(action='ignore', category=FutureWarning)
warnings.filterwarnings("ignore", category=FutureWarning)
import statsmodels.api as sm
from statsmodels.sandbox.regression.predstd import wls_prediction_std
np.random.seed(9876789)
In [12]:
# Criando dados artificiais para uma regressão linear simples
nsample = 100
x = np.linspace(0, 10, 100)
X = np.column_stack((x, x**2))
beta = np.array([1, 0.1, 10])
e = np.random.normal(size=nsample)
In [15]:
X = sm.add_constant(X)
racismo = np.dot(X, beta) + e
In [16]:
model = sm.OLS(racismo, X)
results = model.fit()
print(results.summary())
OLS Regression Results ============================================================================== Dep. Variable: y R-squared: 1.000 Model: OLS Adj. R-squared: 1.000 Method: Least Squares F-statistic: 4.020e+06 Date: Mon, 15 Feb 2021 Prob (F-statistic): 2.83e-239 Time: 14:43:32 Log-Likelihood: -146.51 No. Observations: 100 AIC: 299.0 Df Residuals: 97 BIC: 306.8 Df Model: 2 Covariance Type: nonrobust ============================================================================== coef std err t P>|t| [0.025 0.975] ------------------------------------------------------------------------------ const 1.3423 0.313 4.292 0.000 0.722 1.963 x1 -0.0402 0.145 -0.278 0.781 -0.327 0.247 x2 10.0103 0.014 715.745 0.000 9.982 10.038 ============================================================================== Omnibus: 2.042 Durbin-Watson: 2.274 Prob(Omnibus): 0.360 Jarque-Bera (JB): 1.875 Skew: 0.234 Prob(JB): 0.392 Kurtosis: 2.519 Cond. No. 144. ============================================================================== Notes: [1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
Seaborn: biblioteca Python para gráficos estatísticos¶
In [17]:
import numpy as np
import pandas as pd
import random
import warnings
warnings.filterwarnings("ignore")
import matplotlib as mat
import matplotlib.pyplot as plt
%matplotlib inline
In [18]:
import seaborn as sea
sea.__version__
Out[18]:
'0.11.0'
In [19]:
from pandas import DataFrame
In [30]:
# retomar um exercício da postagem 17:
data = {'Mortes_Maternas': [102, 87, 60, 64, 84, 83, 91, 90, 81],
'Ano': [2009, 2010, 2011, 2012, 2013, 2014, 2015, 2017, 2018],
'RMM': [60.9, 51.9, 33.9, 36.3, 48.5, 47.2, 51.6, 53.1, 48.9]}
In [31]:
frame = DataFrame(data)
frame
Out[31]:
Mortes_Maternas | Ano | RMM | |
---|---|---|---|
0 | 102 | 2009 | 60.9 |
1 | 87 | 2010 | 51.9 |
2 | 60 | 2011 | 33.9 |
3 | 64 | 2012 | 36.3 |
4 | 84 | 2013 | 48.5 |
5 | 83 | 2014 | 47.2 |
6 | 91 | 2015 | 51.6 |
7 | 90 | 2017 | 53.1 |
8 | 81 | 2018 | 48.9 |
In [32]:
# O método joinplot cria plot de 2 variáveis (ano x RMM) com gráficos bivariados e univariados
sea.jointplot("Ano", "RMM", data, kind = 'reg');
Apontamentos
- Não há apontamentos.
BNN - ISSN 1676-4893
Boletim do Núcleo de Estudos e Pesquisas sobre as Atividades de Enfermagem (NEPAE)e do Núcleo de Estudos sobre Saúde e Etnia Negra (NESEN).