{"id":1548,"date":"2023-07-25T22:42:57","date_gmt":"2023-07-25T22:42:57","guid":{"rendered":"https:\/\/statorials.org\/nl\/plot-logistieke-regressie-in-r\/"},"modified":"2023-07-25T22:42:57","modified_gmt":"2023-07-25T22:42:57","slug":"plot-logistieke-regressie-in-r","status":"publish","type":"post","link":"https:\/\/statorials.org\/nl\/plot-logistieke-regressie-in-r\/","title":{"rendered":"Hoe een logistische regressiecurve in r uit te zetten"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">Vaak wilt u misschien de curve van een aangepast logistisch regressiemodel in R uitzetten.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Gelukkig is het vrij eenvoudig om te doen en in deze tutorial wordt uitgelegd hoe je dit moet doen in zowel base R als ggplot2.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Voorbeeld: tekenen van een logistische regressiecurve in basis R<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">De volgende code laat zien hoe u een logistisch regressiemodel kunt aanpassen met behulp van variabelen uit de ingebouwde mtcars-gegevensset in R, en vervolgens hoe u de logistische regressiecurve kunt plotten:<\/span> <\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#fit logistic regression model\n<\/span>model &lt;- glm(vs ~ hp, data=mtcars, family=binomial)\n\n<span style=\"color: #008080;\">#define new data frame that contains predictor variable\n<\/span>newdata &lt;- data. <span style=\"color: #3366ff;\">frame<\/span> (hp=seq(min(mtcars$hp), max(mtcars$hp),len= <span style=\"color: #008000;\">500<\/span> ))\n\n<span style=\"color: #008080;\">#use fitted model to predict values of vs\n<\/span>newdata$vs = predict(model, newdata, type=\" <span style=\"color: #008000;\">response<\/span> \")\n\n<span style=\"color: #008080;\">#plot logistic regression curve\n<\/span>plot(vs ~hp, data=mtcars, col=\" <span style=\"color: #008000;\">steelblue<\/span> \")\nlines(vs ~ hp, newdata, lwd= <span style=\"color: #008000;\">2<\/span> )\n<\/strong><\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-15345\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/courbelogistique1.png\" alt=\"Logistische regressiecurve in basis R\" width=\"453\" height=\"408\" srcset=\"\" sizes=\"auto, \"><\/p>\n<p> <span style=\"color: #000000;\">Op de x-as worden de waarden van de voorspellende variabele <strong>hp<\/strong> weergegeven en op de y-as de voorspelde waarschijnlijkheid van de responsvariabele <strong>am<\/strong> .<\/span><\/p>\n<p> <span style=\"color: #000000;\">We kunnen duidelijk zien dat hogere waarden van de voorspellende variabele <strong>hp<\/strong> verband houden met lagere kansen dat de responsvariabele <strong>versus<\/strong> gelijk is aan 1.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Voorbeeld: een logistische regressiecurve uitzetten in ggplot2<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">De volgende code laat zien hoe u hetzelfde logistische regressiemodel kunt passen en hoe u de logistische regressiecurve kunt plotten met behulp van de <a href=\"https:\/\/ggplot2.tidyverse.org\/\" target=\"_blank\" rel=\"noopener\">ggplot2-<\/a> gegevensvisualisatiebibliotheek:<\/span> <\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><span style=\"color: #000000;\"><span style=\"color: #993300;\">library<\/span> (ggplot2)<\/span><\/span>\n\n<span style=\"color: #008080;\">#plot logistic regression curve\n<\/span>ggplot(mtcars, <span style=\"color: #3366ff;\">aes<\/span> (x=hp, y=vs)) + \n  geom_point(alpha=.5) +\n  stat_smooth(method=\" <span style=\"color: #008000;\">glm<\/span> \", se=FALSE, method. <span style=\"color: #3366ff;\">args<\/span> = list(family=binomial))<\/strong> <\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-15346 \" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/courbelogistique2.png\" alt=\"Logistieke regressiecurve in ggplot2\" width=\"422\" height=\"421\" srcset=\"\" sizes=\"auto, \"><\/p>\n<p> <span style=\"color: #000000;\">Merk op dat dit precies dezelfde curve is die in het vorige voorbeeld is geproduceerd met behulp van de R-basis.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Voel je vrij om ook de stijl van de curve te veranderen. We kunnen de curve bijvoorbeeld in een rode stippellijn veranderen:<\/span> <\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><span style=\"color: #000000;\"><span style=\"color: #993300;\">library<\/span> (ggplot2)<\/span><\/span>\n\n<span style=\"color: #008080;\">#plot logistic regression curve\n<\/span>ggplot(mtcars, <span style=\"color: #3366ff;\">aes<\/span> (x=hp, y=vs)) + \n  geom_point(alpha=.5) +\n  stat_smooth(method=\" <span style=\"color: #008000;\">glm<\/span> \", se=FALSE, method. <span style=\"color: #3366ff;\">args<\/span> = list(family=binomial),\n              col=\" <span style=\"color: #008000;\">red<\/span> \", lty= <span style=\"color: #008000;\">2<\/span> )<\/strong> <\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\" wp-image-15348 aligncenter\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/courbelogistique3.png\" alt=\"\" width=\"403\" height=\"407\" srcset=\"\" sizes=\"auto, \"><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Aanvullende bronnen<\/strong><\/span><\/h3>\n<p> <a href=\"https:\/\/statorials.org\/nl\/logistische-regressie-1\/\" target=\"_blank\" rel=\"noopener\">Inleiding tot logistieke regressie<\/a><br \/> Logistieke regressie uitvoeren in R (stap voor stap)<br \/> <a href=\"https:\/\/statorials.org\/nl\/logistische-regressiepython\/\" target=\"_blank\" rel=\"noopener\">Logistieke regressie uitvoeren in Python (stap voor stap)<\/a><br \/> <a href=\"https:\/\/statorials.org\/nl\/seq-functie-in-r\/\" target=\"_blank\" rel=\"noopener\">Hoe de seq-functie in R te gebruiken<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Vaak wilt u misschien de curve van een aangepast logistisch regressiemodel in R uitzetten. Gelukkig is het vrij eenvoudig om te doen en in deze tutorial wordt uitgelegd hoe je dit moet doen in zowel base R als ggplot2. Voorbeeld: tekenen van een logistische regressiecurve in basis R De volgende code laat zien hoe u [&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-1548","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 een logistische regressiecurve uit te zetten in R - Statorials<\/title>\n<meta name=\"description\" content=\"In deze tutorial wordt uitgelegd hoe u een logistieke regressiecurve in basis R en ggplot2 kunt plotten, inclusief voorbeelden.\" \/>\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\/plot-logistieke-regressie-in-r\/\" \/>\n<meta property=\"og:locale\" content=\"de_DE\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Hoe een logistische regressiecurve uit te zetten in R - Statorials\" \/>\n<meta property=\"og:description\" content=\"In deze tutorial wordt uitgelegd hoe u een logistieke regressiecurve in basis R en ggplot2 kunt plotten, inclusief voorbeelden.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/nl\/plot-logistieke-regressie-in-r\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-25T22:42:57+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/courbelogistique1.png\" \/>\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=\"2\u00a0Minuten\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/statorials.org\/nl\/plot-logistieke-regressie-in-r\/\",\"url\":\"https:\/\/statorials.org\/nl\/plot-logistieke-regressie-in-r\/\",\"name\":\"Hoe een logistische regressiecurve uit te zetten in R - Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/nl\/#website\"},\"datePublished\":\"2023-07-25T22:42:57+00:00\",\"dateModified\":\"2023-07-25T22:42:57+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219\"},\"description\":\"In deze tutorial wordt uitgelegd hoe u een logistieke regressiecurve in basis R en ggplot2 kunt plotten, inclusief voorbeelden.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/nl\/plot-logistieke-regressie-in-r\/#breadcrumb\"},\"inLanguage\":\"de\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/nl\/plot-logistieke-regressie-in-r\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/nl\/plot-logistieke-regressie-in-r\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Thuis\",\"item\":\"https:\/\/statorials.org\/nl\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Hoe een logistische regressiecurve in r uit te zetten\"}]},{\"@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 een logistische regressiecurve uit te zetten in R - Statorials","description":"In deze tutorial wordt uitgelegd hoe u een logistieke regressiecurve in basis R en ggplot2 kunt plotten, inclusief voorbeelden.","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\/plot-logistieke-regressie-in-r\/","og_locale":"de_DE","og_type":"article","og_title":"Hoe een logistische regressiecurve uit te zetten in R - Statorials","og_description":"In deze tutorial wordt uitgelegd hoe u een logistieke regressiecurve in basis R en ggplot2 kunt plotten, inclusief voorbeelden.","og_url":"https:\/\/statorials.org\/nl\/plot-logistieke-regressie-in-r\/","og_site_name":"Statorials","article_published_time":"2023-07-25T22:42:57+00:00","og_image":[{"url":"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/courbelogistique1.png"}],"author":"Dr.benjamin anderson","twitter_card":"summary_large_image","twitter_misc":{"Verfasst von":"Dr.benjamin anderson","Gesch\u00e4tzte Lesezeit":"2\u00a0Minuten"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/statorials.org\/nl\/plot-logistieke-regressie-in-r\/","url":"https:\/\/statorials.org\/nl\/plot-logistieke-regressie-in-r\/","name":"Hoe een logistische regressiecurve uit te zetten in R - Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/nl\/#website"},"datePublished":"2023-07-25T22:42:57+00:00","dateModified":"2023-07-25T22:42:57+00:00","author":{"@id":"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219"},"description":"In deze tutorial wordt uitgelegd hoe u een logistieke regressiecurve in basis R en ggplot2 kunt plotten, inclusief voorbeelden.","breadcrumb":{"@id":"https:\/\/statorials.org\/nl\/plot-logistieke-regressie-in-r\/#breadcrumb"},"inLanguage":"de","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/nl\/plot-logistieke-regressie-in-r\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/nl\/plot-logistieke-regressie-in-r\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Thuis","item":"https:\/\/statorials.org\/nl\/"},{"@type":"ListItem","position":2,"name":"Hoe een logistische regressiecurve in r uit te zetten"}]},{"@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\/1548","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=1548"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/posts\/1548\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/media?parent=1548"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/categories?post=1548"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/tags?post=1548"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}