2014-10-28 14 views
9

Sto cercando un test in Python che fa questo:Python prova proporzione simile a prop.test in R

> survivors <- matrix(c(1781,1443,135,47), ncol=2) 
> colnames(survivors) <- c('survived','died') 
> rownames(survivors) <- c('no seat belt','seat belt') 
> survivors 
      survived died 
no seat belt  1781 135 
seat belt  1443 47 
> prop.test(survivors) 

    2-sample test for equality of proportions with continuity correction 

data: survivors 
X-squared = 24.3328, df = 1, p-value = 8.105e-07 
alternative hypothesis: two.sided 
95 percent confidence interval: 
-0.05400606 -0.02382527 
sample estimates: 
    prop 1 prop 2 
0.9295407 0.9684564 

Sono per lo più interessati a p-value calcolo.

L'esempio è preso forma here

+0

Cosa devo fare per migliorare la mia domanda? – Akavall

+0

Immagino che assomigli un po 'a una domanda "per favore Google per me". Il pacchetto + documentazione di statsmodels potrebbe essere un posto interessante da guardare: http://statsmodels.sourceforge.net/devel/stats.html – cel

+0

@cel, forse è così, ho fatto il mio googling, e penso di alla fine l'ho capito. Se si guarda il nome della funzione è abbastanza diverso, e ho avuto qualche problema a trovarlo dopo aver cercato su Google "test delle proporzioni". – Akavall

risposta

11

penso ho preso:

In [11]: from scipy import stats 

In [12]: import numpy as np 

In [13]: survivors = np.array([[1781,135], [1443, 47]]) 

In [14]: stats.chi2_contingency(survivors) 
Out[14]: 
(24.332761232771361,  # x-squared 
8.1048817984512269e-07, # p-value 
1, 
array([[ 1813.61832061, 102.38167939], 
     [ 1410.38167939, 79.61832061]])) 
Problemi correlati