{"id":2474,"date":"2023-07-22T03:00:29","date_gmt":"2023-07-22T03:00:29","guid":{"rendered":"https:\/\/statorials.org\/nl\/waarschijnlijkheidsratio-test-in-python\/"},"modified":"2023-07-22T03:00:29","modified_gmt":"2023-07-22T03:00:29","slug":"waarschijnlijkheidsratio-test-in-python","status":"publish","type":"post","link":"https:\/\/statorials.org\/nl\/waarschijnlijkheidsratio-test-in-python\/","title":{"rendered":"Hoe u een waarschijnlijkheidsratiotest uitvoert in python"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">Een <strong>waarschijnlijkheidsratiotest<\/strong> vergelijkt de &#8218;goodness of fit&#8216; van twee geneste <a href=\"https:\/\/statorials.org\/nl\/meerdere-lineaire-regressie\/\" target=\"_blank\" rel=\"noopener\">regressiemodellen<\/a> .<\/span><\/p>\n<p> <span style=\"color: #000000;\">Een <a href=\"https:\/\/statorials.org\/nl\/genest-model\/\" target=\"_blank\" rel=\"noopener\">genest model<\/a> is eenvoudigweg een model dat een subset van voorspellende variabelen in het algehele regressiemodel bevat.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Stel dat we bijvoorbeeld het volgende regressiemodel hebben met vier voorspellende variabelen:<\/span><\/p>\n<p> <span style=\"color: #000000;\">Y = \u03b2 <sub>0<\/sub> + \u03b2 <sub>1<\/sub> x <sub>1<\/sub> + \u03b2 <sub>2<\/sub> x <sub>2<\/sub> + \u03b2 <sub>3<\/sub> x <sub>3<\/sub> + \u03b2 <sub>4<\/sub> x <sub>4<\/sub> + \u03b5<\/span><\/p>\n<p> <span style=\"color: #000000;\">Een voorbeeld van een genest model is het volgende model met slechts twee van de oorspronkelijke voorspellende variabelen:<\/span><\/p>\n<p> <span style=\"color: #000000;\">Y = \u03b2 <sub>0<\/sub> + \u03b2 <sub>1<\/sub> x <sub>1<\/sub> + \u03b2 <sub>2<\/sub> x <sub>2<\/sub> + \u03b5<\/span><\/p>\n<p> <span style=\"color: #000000;\">Om te bepalen of deze twee modellen significant van elkaar verschillen, kunnen we een waarschijnlijkheidsratiotest uitvoeren waarbij gebruik wordt gemaakt van de volgende nul- en alternatieve hypothesen:<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>H <sub>0<\/sub> :<\/strong> Het volledige model en het geneste model passen even goed bij de gegevens. U moet dus <strong>een genest model gebruiken<\/strong> .<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>H <sub>A<\/sub> :<\/strong> Het volledige model past aanzienlijk beter bij de gegevens dan het geneste model. U moet dus <strong>het volledige sjabloon gebruiken<\/strong> .<\/span><\/p>\n<p> <span style=\"color: #000000;\">Als de <a href=\"https:\/\/statorials.org\/nl\/p-waarden-statistische-significantie\/\" target=\"_blank\" rel=\"noopener\">p-waarde<\/a> van de test onder een bepaald significantieniveau ligt (bijvoorbeeld 0,05), kunnen we de nulhypothese verwerpen en concluderen dat het volledige model een significant betere fit biedt.<\/span><\/p>\n<p> <span style=\"color: #000000;\">In het volgende stapsgewijze voorbeeld ziet u hoe u een waarschijnlijkheidsratiotest in Python uitvoert.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Stap 1: Gegevens laden<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">In dit voorbeeld laten we zien hoe je de volgende twee regressiemodellen in Python kunt passen met behulp van gegevens uit de <strong>mtcars<\/strong> -gegevensset:<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Volledig model:<\/strong> mpg = \u03b2 <sub>0<\/sub> + \u03b2 <sub>1<\/sub> beschikbaar + \u03b2 <sub>2<\/sub> carb + \u03b2 <sub>3<\/sub> pk + \u03b2 <sub>4<\/sub> cil<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Model:<\/strong> mpg = \u03b2 <sub>0<\/sub> + \u03b2 <sub>1<\/sub> beschikbaar + \u03b2 <sub>2<\/sub> carb<\/span><\/p>\n<p> <span style=\"color: #000000;\">Eerst laden we de dataset:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008000;\">from<\/span> sklearn. <span style=\"color: #3366ff;\">linear_model<\/span> <span style=\"color: #008000;\">import<\/span> LinearRegression\n<span style=\"color: #008000;\">import<\/span> statsmodels. <span style=\"color: #3366ff;\">api<\/span> <span style=\"color: #008000;\">as<\/span> sm\n<span style=\"color: #008000;\">import<\/span> pandas <span style=\"color: #008000;\">as<\/span> pd\n<span style=\"color: #008000;\">import<\/span> scipy\n\n<span style=\"color: #008080;\">#define URL where dataset is located\n<\/span>url = \"https:\/\/raw.githubusercontent.com\/Statorials\/Python-Guides\/main\/mtcars.csv\"\n\n<span style=\"color: #008080;\">#read in data\n<\/span>data = pd. <span style=\"color: #3366ff;\">read_csv<\/span> (url)\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\"><strong>Gerelateerd:<\/strong> <a href=\"https:\/\/statorials.org\/nl\/pandas-lezen-csv\/\" target=\"_blank\" rel=\"noopener\">CSV-bestanden lezen met Panda&#8217;s<\/a><\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Stap 2: Pas de regressiemodellen aan<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Eerst zullen we het volledige model fitten en de log-waarschijnlijkheid van het model berekenen:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#define response variable\n<\/span>y1 = data['mpg']\n\n<span style=\"color: #008080;\">#define predictor variables\n<\/span>x1 = data[['disp', 'carb', 'hp', 'cyl']]\n\n<span style=\"color: #008080;\">#add constant to predictor variables\n<\/span>x1 = sm. <span style=\"color: #3366ff;\">add_constant<\/span> (x1)\n\n<span style=\"color: #008080;\">#fit regression model\n<\/span>full_model = sm. <span style=\"color: #3366ff;\">OLS<\/span> (y1,x1). <span style=\"color: #3366ff;\">fit<\/span> ()\n\n<span style=\"color: #008080;\">#calculate log-likelihood of model\n<\/span>full_ll = full_model. <span style=\"color: #3366ff;\">llf\n<\/span>\n<span style=\"color: #008000;\">print<\/span> (full_ll)\n\n-77.55789711787898\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Vervolgens passen we het gereduceerde model aan en berekenen we de log-waarschijnlijkheid van het model:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#define response variable\n<\/span>y2 = data['mpg']\n\n<span style=\"color: #008080;\">#define predictor variables\n<\/span>x2 = data[['disp', 'carb']]\n\n<span style=\"color: #008080;\">#add constant to predictor variables\n<\/span>x2 = sm. <span style=\"color: #3366ff;\">add_constant<\/span> (x2)\n\n<span style=\"color: #008080;\">#fit regression model\n<\/span>reduced_model = sm. <span style=\"color: #3366ff;\">OLS<\/span> (y2, x2). <span style=\"color: #3366ff;\">fit<\/span> ()\n\n<span style=\"color: #008080;\">#calculate log-likelihood of model\n<\/span>reduced_ll = reduced_model. <span style=\"color: #3366ff;\">llf\n<\/span>\n<span style=\"color: #008000;\">print<\/span> (reduced_ll)\n\n-78.60301334355185\n<\/strong><\/pre>\n<h3> <span style=\"color: #000000;\"><strong>Stap 3: Voer de logwaarschijnlijkheidstest uit<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\"><span style=\"color: #000000;\">Vervolgens zullen we de volgende code gebruiken om de plausibiliteitstest uit te voeren:<\/span><\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <span style=\"color: #000000;\"><strong><span style=\"color: #008080;\">#calculate likelihood ratio Chi-Squared test statistic<\/span>\nLR_statistic = -2 <span style=\"color: #800080;\">*<\/span> (reduced_ll-full_ll)\n\n<span style=\"color: #008000;\">print<\/span> (LR_statistic)\n\n2.0902324513457415\n\n<span style=\"color: #008080;\">#calculate p-value of test statistic using 2 degrees of freedom\n<\/span>p_val = scipy. <span style=\"color: #3366ff;\">stats<\/span> . <span style=\"color: #3366ff;\">chi2<\/span> . <span style=\"color: #3366ff;\">sf<\/span> (LR_statistic, 2)\n\n<span style=\"color: #008000;\">print<\/span> (p_val)\n\n0.35165094613502257\n<\/strong><\/span><\/pre>\n<p> <span style=\"color: #000000;\">Uit het resultaat kunnen we zien dat de chikwadraattoetsstatistiek <strong>2,0902<\/strong> is en de<\/span> <span style=\"color: #000000;\">overeenkomstige p-waarde <strong>0,3517<\/strong> .<\/span><\/p>\n<p> <span style=\"color: #000000;\">Omdat deze p-waarde niet kleiner is dan 0,05, zullen we er niet in slagen de nulhypothese te verwerpen.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Dit betekent dat het volledige model en het geneste model even goed bij de gegevens passen. We moeten daarom het geneste model gebruiken, omdat de extra voorspellende variabelen in het volledige model geen significante verbetering van de fit opleveren.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Ons uiteindelijke model zou dus zijn:<\/span><\/p>\n<p> <span style=\"color: #000000;\">mpg = \u03b2 <sub>0<\/sub> + \u03b2 <sub>1<\/sub> beschikbaar + \u03b2 <sub>2<\/sub> koolhydraten<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Opmerking<\/strong> : We gebruikten 2 vrijheidsgraden bij het berekenen van de p-waarde, omdat dit het verschil vertegenwoordigde in de totale voorspellende variabelen die tussen de twee modellen werden gebruikt.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Aanvullende bronnen<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">De volgende tutorials bieden aanvullende informatie over het gebruik van regressiemodellen in Python:<\/span><\/p>\n<p> <a href=\"https:\/\/statorials.org\/nl\/lineaire-regressiepython\/\" target=\"_blank\" rel=\"noopener\">Een complete gids voor lineaire regressie in Python<\/a><br \/> <a href=\"https:\/\/statorials.org\/nl\/polynomiale-regressiepython\/\" target=\"_blank\" rel=\"noopener\">Hoe polynomiale regressie uit te voeren in Python<\/a><br \/> <a href=\"https:\/\/statorials.org\/nl\/logistische-regressiepython\/\" target=\"_blank\" rel=\"noopener\">Hoe logistieke regressie uit te voeren in Python<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Een waarschijnlijkheidsratiotest vergelijkt de &#8218;goodness of fit&#8216; van twee geneste regressiemodellen . Een genest model is eenvoudigweg een model dat een subset van voorspellende variabelen in het algehele regressiemodel bevat. Stel dat we bijvoorbeeld het volgende regressiemodel hebben met vier voorspellende variabelen: Y = \u03b2 0 + \u03b2 1 x 1 + \u03b2 2 x [&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":[],"class_list":["post-2474","post","type-post","status-publish","format-standard","hentry","category-gids"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Hoe u een waarschijnlijkheidsratiotest uitvoert in Python - Statorials<\/title>\n<meta name=\"description\" content=\"In deze tutorial wordt uitgelegd hoe u een waarschijnlijkheidsratio-test uitvoert in Python, met een compleet voorbeeld.\" \/>\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\/nl\/waarschijnlijkheidsratio-test-in-python\/\" \/>\n<meta property=\"og:locale\" content=\"de_DE\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Hoe u een waarschijnlijkheidsratiotest uitvoert in Python - Statorials\" \/>\n<meta property=\"og:description\" content=\"In deze tutorial wordt uitgelegd hoe u een waarschijnlijkheidsratio-test uitvoert in Python, met een compleet voorbeeld.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/nl\/waarschijnlijkheidsratio-test-in-python\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-22T03:00:29+00:00\" \/>\n<meta name=\"author\" content=\"Dr.benjamin anderson\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Verfasst von\" \/>\n\t<meta name=\"twitter:data1\" content=\"Dr.benjamin anderson\" \/>\n\t<meta name=\"twitter:label2\" content=\"Gesch\u00e4tzte Lesezeit\" \/>\n\t<meta name=\"twitter:data2\" content=\"3\u00a0Minuten\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/statorials.org\/nl\/waarschijnlijkheidsratio-test-in-python\/\",\"url\":\"https:\/\/statorials.org\/nl\/waarschijnlijkheidsratio-test-in-python\/\",\"name\":\"Hoe u een waarschijnlijkheidsratiotest uitvoert in Python - Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/nl\/#website\"},\"datePublished\":\"2023-07-22T03:00:29+00:00\",\"dateModified\":\"2023-07-22T03:00:29+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219\"},\"description\":\"In deze tutorial wordt uitgelegd hoe u een waarschijnlijkheidsratio-test uitvoert in Python, met een compleet voorbeeld.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/nl\/waarschijnlijkheidsratio-test-in-python\/#breadcrumb\"},\"inLanguage\":\"de\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/nl\/waarschijnlijkheidsratio-test-in-python\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/nl\/waarschijnlijkheidsratio-test-in-python\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Thuis\",\"item\":\"https:\/\/statorials.org\/nl\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Hoe u een waarschijnlijkheidsratiotest uitvoert in python\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/statorials.org\/nl\/#website\",\"url\":\"https:\/\/statorials.org\/nl\/\",\"name\":\"Statorials\",\"description\":\"Uw gids voor statistische competentie\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/statorials.org\/nl\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"de\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219\",\"name\":\"Dr.benjamin anderson\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"de\",\"@id\":\"https:\/\/statorials.org\/nl\/#\/schema\/person\/image\/\",\"url\":\"http:\/\/statorials.org\/nl\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"contentUrl\":\"http:\/\/statorials.org\/nl\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"caption\":\"Dr.benjamin anderson\"},\"description\":\"Ik ben Benjamin, een gepensioneerde hoogleraar statistiek die nu een toegewijde Statorials-lesgever is. Ik heb uitgebreide ervaring en expertise op het gebied van statistiek en ik ben vastbesloten om mijn kennis te delen met studenten via Statorials. Lees verder\",\"sameAs\":[\"http:\/\/statorials.org\/nl\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Hoe u een waarschijnlijkheidsratiotest uitvoert in Python - Statorials","description":"In deze tutorial wordt uitgelegd hoe u een waarschijnlijkheidsratio-test uitvoert in Python, met een compleet voorbeeld.","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\/nl\/waarschijnlijkheidsratio-test-in-python\/","og_locale":"de_DE","og_type":"article","og_title":"Hoe u een waarschijnlijkheidsratiotest uitvoert in Python - Statorials","og_description":"In deze tutorial wordt uitgelegd hoe u een waarschijnlijkheidsratio-test uitvoert in Python, met een compleet voorbeeld.","og_url":"https:\/\/statorials.org\/nl\/waarschijnlijkheidsratio-test-in-python\/","og_site_name":"Statorials","article_published_time":"2023-07-22T03:00:29+00:00","author":"Dr.benjamin anderson","twitter_card":"summary_large_image","twitter_misc":{"Verfasst von":"Dr.benjamin anderson","Gesch\u00e4tzte Lesezeit":"3\u00a0Minuten"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/statorials.org\/nl\/waarschijnlijkheidsratio-test-in-python\/","url":"https:\/\/statorials.org\/nl\/waarschijnlijkheidsratio-test-in-python\/","name":"Hoe u een waarschijnlijkheidsratiotest uitvoert in Python - Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/nl\/#website"},"datePublished":"2023-07-22T03:00:29+00:00","dateModified":"2023-07-22T03:00:29+00:00","author":{"@id":"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219"},"description":"In deze tutorial wordt uitgelegd hoe u een waarschijnlijkheidsratio-test uitvoert in Python, met een compleet voorbeeld.","breadcrumb":{"@id":"https:\/\/statorials.org\/nl\/waarschijnlijkheidsratio-test-in-python\/#breadcrumb"},"inLanguage":"de","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/nl\/waarschijnlijkheidsratio-test-in-python\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/nl\/waarschijnlijkheidsratio-test-in-python\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Thuis","item":"https:\/\/statorials.org\/nl\/"},{"@type":"ListItem","position":2,"name":"Hoe u een waarschijnlijkheidsratiotest uitvoert in python"}]},{"@type":"WebSite","@id":"https:\/\/statorials.org\/nl\/#website","url":"https:\/\/statorials.org\/nl\/","name":"Statorials","description":"Uw gids voor statistische competentie","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/statorials.org\/nl\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"de"},{"@type":"Person","@id":"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219","name":"Dr.benjamin anderson","image":{"@type":"ImageObject","inLanguage":"de","@id":"https:\/\/statorials.org\/nl\/#\/schema\/person\/image\/","url":"http:\/\/statorials.org\/nl\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","contentUrl":"http:\/\/statorials.org\/nl\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","caption":"Dr.benjamin anderson"},"description":"Ik ben Benjamin, een gepensioneerde hoogleraar statistiek die nu een toegewijde Statorials-lesgever is. Ik heb uitgebreide ervaring en expertise op het gebied van statistiek en ik ben vastbesloten om mijn kennis te delen met studenten via Statorials. Lees verder","sameAs":["http:\/\/statorials.org\/nl"]}]}},"yoast_meta":{"yoast_wpseo_title":"","yoast_wpseo_metadesc":"","yoast_wpseo_canonical":""},"_links":{"self":[{"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/posts\/2474","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/comments?post=2474"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/posts\/2474\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/media?parent=2474"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/categories?post=2474"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/tags?post=2474"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}