{"id":1126,"date":"2023-07-27T14:05:00","date_gmt":"2023-07-27T14:05:00","guid":{"rendered":"https:\/\/statorials.org\/it\/una-proporzione-z-test-pitone\/"},"modified":"2023-07-27T14:05:00","modified_gmt":"2023-07-27T14:05:00","slug":"una-proporzione-z-test-pitone","status":"publish","type":"post","link":"https:\/\/statorials.org\/it\/una-proporzione-z-test-pitone\/","title":{"rendered":"Come eseguire un test z a una proporzione in python"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">Un <a href=\"https:\/\/statorials.org\/it\/un-test-z-delle-proporzioni\/\" target=\"_blank\" rel=\"noopener noreferrer\">test z su una proporzione<\/a> viene utilizzato per confrontare una proporzione osservata con una proporzione teorica.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Questo test utilizza le seguenti ipotesi nulle:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\"><strong>H <sub>0<\/sub> :<\/strong> p = p <sub>0<\/sub> (la proporzione della popolazione \u00e8 uguale alla proporzione ipotetica p <sub>0<\/sub> )<\/span><\/li>\n<\/ul>\n<p> <span style=\"color: #000000;\">L\u2019ipotesi alternativa pu\u00f2 essere bilaterale, sinistra o destra:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\"><strong>H <sub>1<\/sub> (a due code):<\/strong> p \u2260 p <sub>0<\/sub> (la proporzione della popolazione non \u00e8 uguale a un valore ipotetico p <sub>0<\/sub> )<\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong>H <sub>1<\/sub> (a sinistra):<\/strong> p &lt; p <sub>0<\/sub> (la proporzione della popolazione \u00e8 inferiore a un valore ipotetico p <sub>0<\/sub> )<\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong>H <sub>1<\/sub> (a destra):<\/strong> p &gt; p <sub>0<\/sub> (la proporzione della popolazione \u00e8 maggiore di un ipotetico valore p <sub>0<\/sub> )<\/span><\/li>\n<\/ul>\n<p> <span style=\"color: #000000;\">La statistica del test viene calcolata come segue:<\/span><\/p>\n<p> <span style=\"color: #000000;\">z = (pp <sub>0<\/sub> ) \/ \u221a <span style=\"border-top: 1px solid black;\">p <sub>0<\/sub> (1-p <sub>0<\/sub> )\/n<\/span><\/span><\/p>\n<p> <span style=\"color: #000000;\">Oro:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\"><strong>p:<\/strong> proporzione campionaria osservata<\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong>p <sub>0<\/sub> :<\/strong> proporzione ipotetica della popolazione<\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong>n:<\/strong> dimensione del campione<\/span><\/li>\n<\/ul>\n<p> <span style=\"color: #000000;\">Se il valore p che corrisponde alla statistica del test z \u00e8 inferiore al livello di significativit\u00e0 scelto (le scelte comuni sono 0,10, 0,05 e 0,01), \u00e8 possibile rifiutare l&#8217;ipotesi nulla.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Un test della proporzione Z in Python<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Per eseguire uno z-test su una proporzione in Python, possiamo utilizzare la funzione <a href=\"https:\/\/www.statsmodels.org\/stable\/generated\/statsmodels.stats.proportion.proportions_ztest.html\" target=\"_blank\" rel=\"noopener noreferrer\">Recommendations_ztest()<\/a> dalla libreria <strong>statsmodels<\/strong> , che utilizza la seguente sintassi:<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>proporzioni_ztest(conteggio, nobs, valore=Nessuno, alternativa=&#8217;due facce&#8217;)<\/strong><\/span><\/p>\n<p> <span style=\"color: #000000;\">Oro:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\"><strong>conteggio:<\/strong> il numero di successi<\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong>nobs:<\/strong> il numero di tentativi<\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong>valore:<\/strong> la proporzione ipotetica della popolazione<\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong>alternativa:<\/strong> l&#8217;ipotesi alternativa<\/span><\/li>\n<\/ul>\n<p> <span style=\"color: #000000;\">Questa funzione restituisce una statistica di test az e un valore p corrispondente.<\/span><\/p>\n<p> <span style=\"color: #000000;\">L&#8217;esempio seguente mostra come utilizzare questa funzione per eseguire uno z-test a una proporzione in Python.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Esempio: un test della proporzione Z in Python<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Supponiamo di voler sapere se la percentuale di residenti in una determinata contea che sostengono una determinata legge \u00e8 pari o meno al 60%. Per verificarlo, raccogliamo i seguenti dati su un campione casuale:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\"><strong>p <sub>0<\/sub> :<\/strong> proporzione ipotetica della popolazione = 0,60<\/span><\/li>\n<li> <span style=\"color: #000000;\"><b>x:<\/b> residenti favorevoli alla legge: 64<\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong>n:<\/strong> dimensione del campione = 100<\/span><\/li>\n<\/ul>\n<p> <span style=\"color: #000000;\">Il codice seguente mostra come utilizzare la funzione <strong>Recommendations_ztest<\/strong> per eseguire un test az su un campione:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008000;\"><span style=\"color: #008080;\">#import proportions_ztest function<\/span>\nfrom<\/span> statsmodels. <span style=\"color: #3366ff;\">stats.proportion<\/span> <span style=\"color: #008000;\">import<\/span> proportions_ztest\n\n<span style=\"color: #008080;\">#perform one proportion z-test\n<\/span>proportions_ztest(count= <span style=\"color: #008000;\">60<\/span> , nobs= <span style=\"color: #008000;\">100<\/span> , value= <span style=\"color: #008000;\">0.64<\/span> )\n(-0.8164965809277268, 0.41421617824252466)<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Dal risultato, possiamo vedere che la statistica del test z \u00e8 <strong>-0,8165<\/strong> e il corrispondente valore p \u00e8 <strong>0,4142<\/strong> . Poich\u00e9 questo valore non \u00e8 inferiore a \u03b1 = 0,05, non riusciamo a rifiutare l&#8217;ipotesi nulla. Non abbiamo prove sufficienti per affermare che la percentuale di residenti favorevoli alla legge sia diversa da 0,60.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Risorse addizionali<\/strong><\/span><\/h3>\n<p> <a href=\"https:\/\/statorials.org\/it\/un-test-z-delle-proporzioni\/\" target=\"_blank\" rel=\"noopener noreferrer\">Un&#8217;introduzione al test Z della proporzione singola<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/un-calcolatore-della-proporzione-del-test-z\/\" target=\"_blank\" rel=\"noopener noreferrer\">Una calcolatrice per il test della proporzione Z<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/una-proporzione-z-test-excel\/\" target=\"_blank\" rel=\"noopener noreferrer\">Come eseguire un test Z di una proporzione in Excel<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/un-test-della-proporzione-z-in-r\/\" target=\"_blank\" rel=\"noopener noreferrer\">Come eseguire un test Z ad una proporzione in R<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Un test z su una proporzione viene utilizzato per confrontare una proporzione osservata con una proporzione teorica. Questo test utilizza le seguenti ipotesi nulle: H 0 : p = p 0 (la proporzione della popolazione \u00e8 uguale alla proporzione ipotetica p 0 ) L\u2019ipotesi alternativa pu\u00f2 essere bilaterale, sinistra o destra: H 1 (a due [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Come eseguire un test Z a una proporzione in Python<\/title>\n<meta name=\"description\" content=\"Questo tutorial spiega come eseguire uno z-test con una proporzione in Python, con diversi esempi.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/statorials.org\/it\/una-proporzione-z-test-pitone\/\" \/>\n<meta property=\"og:locale\" content=\"it_IT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Come eseguire un test Z a una proporzione in Python\" \/>\n<meta property=\"og:description\" content=\"Questo tutorial spiega come eseguire uno z-test con una proporzione in Python, con diversi esempi.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/it\/una-proporzione-z-test-pitone\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-27T14:05:00+00:00\" \/>\n<meta name=\"author\" content=\"Benjamin anderson\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Benjamin anderson\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minuti\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/statorials.org\/it\/una-proporzione-z-test-pitone\/\",\"url\":\"https:\/\/statorials.org\/it\/una-proporzione-z-test-pitone\/\",\"name\":\"Come eseguire un test Z a una proporzione in Python\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/it\/#website\"},\"datePublished\":\"2023-07-27T14:05:00+00:00\",\"dateModified\":\"2023-07-27T14:05:00+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae\"},\"description\":\"Questo tutorial spiega come eseguire uno z-test con una proporzione in Python, con diversi esempi.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/it\/una-proporzione-z-test-pitone\/#breadcrumb\"},\"inLanguage\":\"it-IT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/it\/una-proporzione-z-test-pitone\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/it\/una-proporzione-z-test-pitone\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Casa\",\"item\":\"https:\/\/statorials.org\/it\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Come eseguire un test z a una proporzione in python\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/statorials.org\/it\/#website\",\"url\":\"https:\/\/statorials.org\/it\/\",\"name\":\"Statorials\",\"description\":\"La tua guida all&#039;alfabetizzazione statistica!\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/statorials.org\/it\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"it-IT\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae\",\"name\":\"Benjamin anderson\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"it-IT\",\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/statorials.org\/it\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"contentUrl\":\"https:\/\/statorials.org\/it\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"caption\":\"Benjamin anderson\"},\"description\":\"Ciao, sono Benjamin, un professore di statistica in pensione diventato insegnante dedicato di Statorials. Con una vasta esperienza e competenza nel campo della statistica, sono ansioso di condividere le mie conoscenze per potenziare gli studenti attraverso Statorials. Scopri di pi\u00f9\",\"sameAs\":[\"https:\/\/statorials.org\/it\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Come eseguire un test Z a una proporzione in Python","description":"Questo tutorial spiega come eseguire uno z-test con una proporzione in Python, con diversi esempi.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/statorials.org\/it\/una-proporzione-z-test-pitone\/","og_locale":"it_IT","og_type":"article","og_title":"Come eseguire un test Z a una proporzione in Python","og_description":"Questo tutorial spiega come eseguire uno z-test con una proporzione in Python, con diversi esempi.","og_url":"https:\/\/statorials.org\/it\/una-proporzione-z-test-pitone\/","og_site_name":"Statorials","article_published_time":"2023-07-27T14:05:00+00:00","author":"Benjamin anderson","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Benjamin anderson","Est. reading time":"2 minuti"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/statorials.org\/it\/una-proporzione-z-test-pitone\/","url":"https:\/\/statorials.org\/it\/una-proporzione-z-test-pitone\/","name":"Come eseguire un test Z a una proporzione in Python","isPartOf":{"@id":"https:\/\/statorials.org\/it\/#website"},"datePublished":"2023-07-27T14:05:00+00:00","dateModified":"2023-07-27T14:05:00+00:00","author":{"@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae"},"description":"Questo tutorial spiega come eseguire uno z-test con una proporzione in Python, con diversi esempi.","breadcrumb":{"@id":"https:\/\/statorials.org\/it\/una-proporzione-z-test-pitone\/#breadcrumb"},"inLanguage":"it-IT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/it\/una-proporzione-z-test-pitone\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/it\/una-proporzione-z-test-pitone\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Casa","item":"https:\/\/statorials.org\/it\/"},{"@type":"ListItem","position":2,"name":"Come eseguire un test z a una proporzione in python"}]},{"@type":"WebSite","@id":"https:\/\/statorials.org\/it\/#website","url":"https:\/\/statorials.org\/it\/","name":"Statorials","description":"La tua guida all&#039;alfabetizzazione statistica!","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/statorials.org\/it\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"it-IT"},{"@type":"Person","@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae","name":"Benjamin anderson","image":{"@type":"ImageObject","inLanguage":"it-IT","@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/image\/","url":"https:\/\/statorials.org\/it\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","contentUrl":"https:\/\/statorials.org\/it\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","caption":"Benjamin anderson"},"description":"Ciao, sono Benjamin, un professore di statistica in pensione diventato insegnante dedicato di Statorials. Con una vasta esperienza e competenza nel campo della statistica, sono ansioso di condividere le mie conoscenze per potenziare gli studenti attraverso Statorials. Scopri di pi\u00f9","sameAs":["https:\/\/statorials.org\/it"]}]}},"yoast_meta":{"yoast_wpseo_title":"","yoast_wpseo_metadesc":"","yoast_wpseo_canonical":""},"_links":{"self":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts\/1126"}],"collection":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/comments?post=1126"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts\/1126\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/media?parent=1126"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/categories?post=1126"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/tags?post=1126"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}