{"id":4508,"date":"2023-07-10T13:33:15","date_gmt":"2023-07-10T13:33:15","guid":{"rendered":"https:\/\/statorials.org\/nl\/stepaische-r\/"},"modified":"2023-07-10T13:33:15","modified_gmt":"2023-07-10T13:33:15","slug":"stepaische-r","status":"publish","type":"post","link":"https:\/\/statorials.org\/nl\/stepaische-r\/","title":{"rendered":"Hoe stepaic in r te gebruiken voor functieselectie"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">Het Akaike Information Criterion ( <strong>AIC<\/strong> ) is een metriek die wordt gebruikt om te kwantificeren hoe goed een model bij een dataset past.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Het wordt als volgt berekend:<\/span><\/p>\n<p> <strong><span style=\"color: #000000;\">AIC = 2K \u2013 2 <em>ln<\/em> (L)<\/span><\/strong><\/p>\n<p> <span style=\"color: #000000;\">Goud:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\"><strong>K:<\/strong> Het aantal modelparameters. De standaardwaarde van K is 2, dus een model met slechts \u00e9\u00e9n voorspellende variabele heeft een K-waarde van 2+1 = 3.<\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong><em>ln<\/em> (L)<\/strong> : De log-waarschijnlijkheid van het model. De meeste statistische software kan deze waarde automatisch voor u berekenen.<\/span><\/li>\n<\/ul>\n<p> <span style=\"color: #000000;\">AIC is ontworpen om het model te vinden dat de meeste variatie in de gegevens verklaart, terwijl modellen worden bestraft die een buitensporig aantal parameters gebruiken.<\/span><\/p>\n<p> <span style=\"color: #000000;\">U kunt de functie <strong>stepAIC()<\/strong> uit het <strong>MASS-<\/strong> pakket in R gebruiken om iteratief voorspellingsvariabelen toe te voegen aan en te verwijderen uit een regressiemodel totdat u de set voorspellingsvariabelen (of &#8222;features&#8220;) vindt die het model met de laagste AIC-waarde produceert.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Deze functie gebruikt de volgende basissyntaxis:<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>stapAIC(object, richting, \u2026)<\/strong><\/span><\/p>\n<p> <span style=\"color: #000000;\">Goud:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\"><strong>object<\/strong> : De naam van een aangepast model<\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong>richting<\/strong> : het type stapzoekopdracht dat u wilt gebruiken (\u201cachteruit\u201d, \u201cvooruit\u201d of \u201cbeide\u201d)<\/span><\/li>\n<\/ul>\n<p> <span style=\"color: #000000;\">Het volgende voorbeeld laat zien hoe u deze functie in de praktijk kunt gebruiken.<\/span><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Voorbeeld: stepAIC() gebruiken voor objectselectie in R<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">Voor dit voorbeeld gebruiken we de <a href=\"https:\/\/statorials.org\/nl\/mtcars-r-gegevensset\/\" target=\"_blank\" rel=\"noopener\">mtcars-<\/a> dataset die is ingebouwd in R, die metingen bevat van 11 verschillende attributen voor 32 verschillende auto&#8217;s:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <span style=\"color: #008080;\"><strong>#view first six rows of mtcars dataset<\/strong><\/span>\n<strong>head(mtcars)\n\n                   mpg cyl disp hp drat wt qsec vs am gear carb\nMazda RX4 21.0 6 160 110 3.90 2.620 16.46 0 1 4 4\nMazda RX4 Wag 21.0 6 160 110 3.90 2.875 17.02 0 1 4 4\nDatsun 710 22.8 4 108 93 3.85 2.320 18.61 1 1 4 1\nHornet 4 Drive 21.4 6 258 110 3.08 3.215 19.44 1 0 3 1\nHornet Sportabout 18.7 8 360 175 3.15 3.440 17.02 0 0 3 2\nValiant 18.1 6 225 105 2.76 3,460 20.22 1 0 3 1\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Stel dat we een regressiemodel willen fitten met <strong>hp<\/strong> als responsvariabele en de volgende potenti\u00eble voorspellende variabelen:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\"><strong>mpg<\/strong><\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong>gewicht<\/strong><\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong>shit<\/strong><\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong>qsec<\/strong><\/span><\/li>\n<\/ul>\n<p> <span style=\"color: #000000;\">We kunnen de functie <strong>stepAIC()<\/strong> uit het <b>MASS-<\/b> pakket gebruiken om verschillende voorspellende variabelen uit het model op te tellen en af te trekken totdat we bij het model komen met de laagst mogelijke AIC-waarde:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <span style=\"color: #000000;\"><strong><span style=\"color: #008000;\">library<\/span> (MASS)\n\n<span style=\"color: #008080;\">#fit initial multiple linear regression model\n<\/span>model &lt;- lm(hp ~ mpg + wt + drat + qsec, data=mtcars)\n\n<span style=\"color: #008080;\">#use both forward and backward selection to find model with lowest AIC\n<\/span>stepAIC(model, direction=\" <span style=\"color: #ff0000;\">both<\/span> \")\n\nStart: AIC=226.88\nhp ~ mpg + wt + drat + qsec\n\n       Df Sum of Sq RSS AIC\n- drat 1 94.9 28183 224.98\n- mpg 1 1519.4 29608 226.56\n  none 28088 226.88\n- wt 1 3861.9 31950 229.00\n-qsec 1 28102.2 56190 247.06\n\nStep: AIC=224.98\nhp ~ mpg + wt + qsec\n\n       Df Sum of Sq RSS AIC\n- mpg 1 1424.5 29608 224.56\n  none 28183 224.98\n+ drat 1 94.9 28088 226.88\n- wt 1 3797.9 31981 227.03\n-qsec 1 29625.1 57808 245.97\n\nStep: AIC=224.56\nhp ~ wt + qsec\n\n       Df Sum of Sq RSS AIC\n  none 29608 224.56\n+ mpg 1 1425 28183 224.98\n+ drat 1 0 29608 226.56\n- wt 1 43026 72633 251.28\n-qsec 1 52881 82489 255.35\n\nCall:\nlm(formula = hp ~ wt + qsec, data = mtcars)\n\nCoefficients:\n(Intercept) wt qsec  \n     441.26 38.67 -23.47  \n<\/strong><\/span><\/pre>\n<p> <span style=\"color: #000000;\">Zo interpreteert u het resultaat:<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>(1)<\/strong> Eerst beginnen we met het fitten van een regressiemodel met de vier voorspellende variabelen. Dit model heeft een AIC-waarde van <strong>226,88<\/strong> .<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>(2)<\/strong> Vervolgens bepaalt stepAIC dat het verwijderen van <strong>drat<\/strong> als voorspellende variabele de AIC-waarde verder zal verlagen tot <strong>224,98<\/strong> .<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>(3)<\/strong> Vervolgens bepaalt het stepAIC-model dat het verwijderen van <strong>mpg<\/strong> als voorspellende variabele de AIC-waarde verder zal verlagen tot <strong>224,56<\/strong> .<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>(4)<\/strong> Ten slotte bepaalt stepAIC dat er geen manier is om de AIC-waarde verder te verlagen door variabelen toe te voegen of te verwijderen.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Het uiteindelijke model is daarom:<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>pk = 441,26 + 38,67 (gewicht) \u2013 23,47 (qsec)<\/strong><\/span><\/p>\n<p> <span style=\"color: #000000;\">Dit model heeft een AIC-waarde van <strong>224,56<\/strong> .<\/span><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Aanvullende bronnen<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">In de volgende tutorials wordt uitgelegd hoe u andere veelvoorkomende taken in R kunt uitvoeren:<\/span><\/p>\n<p> <span style=\"color: #000000;\"><a href=\"https:\/\/statorials.org\/nl\/meervoudige-lineaire-regressie-r\/\" target=\"_blank\" rel=\"noopener\">Hoe meervoudige lineaire regressie uit te voeren in R<\/a><br \/> <a href=\"https:\/\/statorials.org\/nl\/stuksgewijze-regressie-in-r\/\" target=\"_blank\" rel=\"noopener\">Hoe stuksgewijs regressie uit te voeren in R<\/a><br \/> <a href=\"https:\/\/statorials.org\/nl\/spline-regressie-in-r\/\" target=\"_blank\" rel=\"noopener\">Hoe spline-regressie uit te voeren in R<\/a><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Het Akaike Information Criterion ( AIC ) is een metriek die wordt gebruikt om te kwantificeren hoe goed een model bij een dataset past. Het wordt als volgt berekend: AIC = 2K \u2013 2 ln (L) Goud: K: Het aantal modelparameters. De standaardwaarde van K is 2, dus een model met slechts \u00e9\u00e9n voorspellende variabele [&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-4508","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 stepAIC in R te gebruiken voor functieselectie - Statorials<\/title>\n<meta name=\"description\" content=\"In deze tutorial wordt met een voorbeeld uitgelegd hoe u de stepAIC-functie in R kunt gebruiken om modelselectie uit te voeren met behulp van AIC.\" \/>\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\/stepaische-r\/\" \/>\n<meta property=\"og:locale\" content=\"de_DE\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Hoe stepAIC in R te gebruiken voor functieselectie - Statorials\" \/>\n<meta property=\"og:description\" content=\"In deze tutorial wordt met een voorbeeld uitgelegd hoe u de stepAIC-functie in R kunt gebruiken om modelselectie uit te voeren met behulp van AIC.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/nl\/stepaische-r\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-10T13:33:15+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\/stepaische-r\/\",\"url\":\"https:\/\/statorials.org\/nl\/stepaische-r\/\",\"name\":\"Hoe stepAIC in R te gebruiken voor functieselectie - Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/nl\/#website\"},\"datePublished\":\"2023-07-10T13:33:15+00:00\",\"dateModified\":\"2023-07-10T13:33:15+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219\"},\"description\":\"In deze tutorial wordt met een voorbeeld uitgelegd hoe u de stepAIC-functie in R kunt gebruiken om modelselectie uit te voeren met behulp van AIC.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/nl\/stepaische-r\/#breadcrumb\"},\"inLanguage\":\"de\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/nl\/stepaische-r\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/nl\/stepaische-r\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Thuis\",\"item\":\"https:\/\/statorials.org\/nl\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Hoe stepaic in r te gebruiken voor functieselectie\"}]},{\"@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 stepAIC in R te gebruiken voor functieselectie - Statorials","description":"In deze tutorial wordt met een voorbeeld uitgelegd hoe u de stepAIC-functie in R kunt gebruiken om modelselectie uit te voeren met behulp van AIC.","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\/stepaische-r\/","og_locale":"de_DE","og_type":"article","og_title":"Hoe stepAIC in R te gebruiken voor functieselectie - Statorials","og_description":"In deze tutorial wordt met een voorbeeld uitgelegd hoe u de stepAIC-functie in R kunt gebruiken om modelselectie uit te voeren met behulp van AIC.","og_url":"https:\/\/statorials.org\/nl\/stepaische-r\/","og_site_name":"Statorials","article_published_time":"2023-07-10T13:33:15+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\/stepaische-r\/","url":"https:\/\/statorials.org\/nl\/stepaische-r\/","name":"Hoe stepAIC in R te gebruiken voor functieselectie - Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/nl\/#website"},"datePublished":"2023-07-10T13:33:15+00:00","dateModified":"2023-07-10T13:33:15+00:00","author":{"@id":"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219"},"description":"In deze tutorial wordt met een voorbeeld uitgelegd hoe u de stepAIC-functie in R kunt gebruiken om modelselectie uit te voeren met behulp van AIC.","breadcrumb":{"@id":"https:\/\/statorials.org\/nl\/stepaische-r\/#breadcrumb"},"inLanguage":"de","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/nl\/stepaische-r\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/nl\/stepaische-r\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Thuis","item":"https:\/\/statorials.org\/nl\/"},{"@type":"ListItem","position":2,"name":"Hoe stepaic in r te gebruiken voor functieselectie"}]},{"@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\/4508","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=4508"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/posts\/4508\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/media?parent=4508"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/categories?post=4508"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/tags?post=4508"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}