{"id":1586,"date":"2023-07-25T18:29:30","date_gmt":"2023-07-25T18:29:30","guid":{"rendered":"https:\/\/statorials.org\/nl\/nee-in-r\/"},"modified":"2023-07-25T18:29:30","modified_gmt":"2023-07-25T18:29:30","slug":"nee-in-r","status":"publish","type":"post","link":"https:\/\/statorials.org\/nl\/nee-in-r\/","title":{"rendered":"Hoe de auc (oppervlakte onder de curve) in r te berekenen"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\"><a href=\"https:\/\/statorials.org\/nl\/logistische-regressie-1\/\" target=\"_blank\" rel=\"noopener noreferrer\">Logistische regressie<\/a> is een statistische methode die we gebruiken om een regressiemodel te fitten wanneer de responsvariabele binair is. Om te evalueren hoe goed een logistisch regressiemodel bij een dataset past, kunnen we naar de volgende twee statistieken kijken:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\"><strong>Gevoeligheid:<\/strong> waarschijnlijkheid dat het model een positief resultaat voorspelt voor een waarneming terwijl het resultaat daadwerkelijk positief is. Dit wordt ook wel het \u201cechte positieve percentage\u201d genoemd.<\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong>Specificiteit:<\/strong> de kans dat het model een negatief resultaat voorspelt voor een waarneming terwijl het resultaat feitelijk negatief is. Dit wordt ook wel het \u2018echte negatieve tarief\u2019 genoemd.<\/span><\/li>\n<\/ul>\n<p> <span style=\"color: #000000;\">E\u00e9n manier om deze twee metingen te visualiseren is door een <strong>ROC-curve<\/strong> te maken, wat staat voor \u2018receiver operating karakteristieke\u2019-curve.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Dit is een grafiek die de gevoeligheid langs de y-as en (1 \u2013 specificiteit) langs de x-as weergeeft. E\u00e9n manier om de effectiviteit van het logistische regressiemodel bij het classificeren van gegevens te kwantificeren is door <strong>de AUC<\/strong> te berekenen, wat staat voor &#8218;area under the curve&#8216;.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Hoe dichter de AUC bij 1 ligt, hoe beter het model.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Het volgende stapsgewijze voorbeeld laat zien hoe u de AUC voor een logistisch regressiemodel in R kunt berekenen.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Stap 1: Gegevens laden<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Eerst laden we de <strong>standaarddataset<\/strong> uit het <strong>ISLR-<\/strong> pakket, die informatie bevat over de vraag of verschillende mensen al dan niet in gebreke zijn gebleven bij het betalen van een lening.<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#load dataset\n<\/span>data &lt;- ISLR::Default\n\n<span style=\"color: #008080;\">#view first six rows of dataset\n<\/span>head(data)\n\n  default student balance income\n1 No No 729.5265 44361.625\n2 No Yes 817.1804 12106.135\n3 No No 1073.5492 31767.139\n4 No No 529.2506 35704.494\n5 No No 785.6559 38463.496\n6 No Yes 919.5885 7491.559\n<\/strong><\/pre>\n<h3> <span style=\"color: #000000;\"><strong>Stap 2: Pas het logistische regressiemodel aan<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Vervolgens passen we een logistisch regressiemodel toe om de waarschijnlijkheid te voorspellen dat een individu in gebreke blijft:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#make this example reproducible\n<\/span>set. <span style=\"color: #3366ff;\">seeds<\/span> (1)\n\n<span style=\"color: #008080;\">#Use 70% of dataset as training set and remaining 30% as testing set\n<\/span>sample &lt;- sample(c(TRUE, FALSE), nrow(data), replace= <span style=\"color: #008000;\">TRUE<\/span> , prob=c(0.7,0.3))\ntrain &lt;- data[sample, ]\ntest &lt;- data[!sample, ] \n\n<span style=\"color: #008080;\">#fit logistic regression model\n<\/span>model &lt;- glm(default~student+balance+income, family=\" <span style=\"color: #008000;\">binomial<\/span> \", data=train)<\/strong><\/pre>\n<h3> <span style=\"color: #000000;\"><strong>Stap 3: Bereken model-AUC<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Vervolgens zullen we de functie <strong>auc()<\/strong> uit het <strong>pROC-<\/strong> pakket gebruiken om de AUC van het model te berekenen. Deze functie gebruikt de volgende syntaxis:<\/span><\/p>\n<p> <strong><span style=\"color: #000000;\">geen (antwoord, voorspeld)<\/span><\/strong><\/p>\n<p> <span style=\"color: #000000;\">Zo gebruikt u deze functie in ons voorbeeld:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#calculate probability of default for each individual in test dataset\n<\/span>predicted &lt;- predict(model, test, type=\" <span style=\"color: #008000;\">response<\/span> \")\n\n<span style=\"color: #008080;\">#calculate AUC\n<\/span><span style=\"color: #993300;\">library<\/span> (pROC)\nauc(test$default, predicted)\n\nSetting levels: control = No, case = Yes\nSetting direction: controls &lt; boxes\nArea under the curve: 0.9437\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">De AUC van het model blijkt <strong>0,9437<\/strong> te zijn.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Omdat deze waarde dicht bij 1 ligt, geeft dit aan dat het model heel goed kan voorspellen of een individu wel of niet in gebreke zal blijven met zijn lening.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Logistische regressie is een statistische methode die we gebruiken om een regressiemodel te fitten wanneer de responsvariabele binair is. Om te evalueren hoe goed een logistisch regressiemodel bij een dataset past, kunnen we naar de volgende twee statistieken kijken: Gevoeligheid: waarschijnlijkheid dat het model een positief resultaat voorspelt voor een waarneming terwijl het resultaat daadwerkelijk [&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-1586","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 de AUC (oppervlakte onder de curve) te berekenen in R - Statorials<\/title>\n<meta name=\"description\" content=\"In deze tutorial wordt uitgelegd hoe u de AUC (area under curve) in R kunt berekenen, inclusief een stapsgewijs 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\/nee-in-r\/\" \/>\n<meta property=\"og:locale\" content=\"de_DE\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Hoe de AUC (oppervlakte onder de curve) te berekenen in R - Statorials\" \/>\n<meta property=\"og:description\" content=\"In deze tutorial wordt uitgelegd hoe u de AUC (area under curve) in R kunt berekenen, inclusief een stapsgewijs voorbeeld.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/nl\/nee-in-r\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-25T18:29:30+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=\"2\u00a0Minuten\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/statorials.org\/nl\/nee-in-r\/\",\"url\":\"https:\/\/statorials.org\/nl\/nee-in-r\/\",\"name\":\"Hoe de AUC (oppervlakte onder de curve) te berekenen in R - Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/nl\/#website\"},\"datePublished\":\"2023-07-25T18:29:30+00:00\",\"dateModified\":\"2023-07-25T18:29:30+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219\"},\"description\":\"In deze tutorial wordt uitgelegd hoe u de AUC (area under curve) in R kunt berekenen, inclusief een stapsgewijs voorbeeld.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/nl\/nee-in-r\/#breadcrumb\"},\"inLanguage\":\"de\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/nl\/nee-in-r\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/nl\/nee-in-r\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Thuis\",\"item\":\"https:\/\/statorials.org\/nl\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Hoe de auc (oppervlakte onder de curve) in r te berekenen\"}]},{\"@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 de AUC (oppervlakte onder de curve) te berekenen in R - Statorials","description":"In deze tutorial wordt uitgelegd hoe u de AUC (area under curve) in R kunt berekenen, inclusief een stapsgewijs 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\/nee-in-r\/","og_locale":"de_DE","og_type":"article","og_title":"Hoe de AUC (oppervlakte onder de curve) te berekenen in R - Statorials","og_description":"In deze tutorial wordt uitgelegd hoe u de AUC (area under curve) in R kunt berekenen, inclusief een stapsgewijs voorbeeld.","og_url":"https:\/\/statorials.org\/nl\/nee-in-r\/","og_site_name":"Statorials","article_published_time":"2023-07-25T18:29:30+00:00","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\/nee-in-r\/","url":"https:\/\/statorials.org\/nl\/nee-in-r\/","name":"Hoe de AUC (oppervlakte onder de curve) te berekenen in R - Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/nl\/#website"},"datePublished":"2023-07-25T18:29:30+00:00","dateModified":"2023-07-25T18:29:30+00:00","author":{"@id":"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219"},"description":"In deze tutorial wordt uitgelegd hoe u de AUC (area under curve) in R kunt berekenen, inclusief een stapsgewijs voorbeeld.","breadcrumb":{"@id":"https:\/\/statorials.org\/nl\/nee-in-r\/#breadcrumb"},"inLanguage":"de","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/nl\/nee-in-r\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/nl\/nee-in-r\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Thuis","item":"https:\/\/statorials.org\/nl\/"},{"@type":"ListItem","position":2,"name":"Hoe de auc (oppervlakte onder de curve) in r te berekenen"}]},{"@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\/1586","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=1586"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/posts\/1586\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/media?parent=1586"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/categories?post=1586"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/tags?post=1586"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}