{"id":4268,"date":"2023-07-12T10:12:56","date_gmt":"2023-07-12T10:12:56","guid":{"rendered":"https:\/\/statorials.org\/nl\/extraheer-de-residuen-van-lm-in-r\/"},"modified":"2023-07-12T10:12:56","modified_gmt":"2023-07-12T10:12:56","slug":"extraheer-de-residuen-van-lm-in-r","status":"publish","type":"post","link":"https:\/\/statorials.org\/nl\/extraheer-de-residuen-van-lm-in-r\/","title":{"rendered":"Hoe residuen uit de lm()-functie in r te extraheren"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">U kunt de volgende syntaxis gebruiken om <a href=\"https:\/\/statorials.org\/nl\/residu\/\" target=\"_blank\" rel=\"noopener\">residuen<\/a> uit de functie <a href=\"https:\/\/statorials.org\/nl\/lm-functie-in-r\/\" target=\"_blank\" rel=\"noopener\">lm()<\/a> in R te extraheren:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #000000;\">fit$residuals<\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">In dit voorbeeld wordt ervan uitgegaan dat we de functie <strong>lm()<\/strong> hebben gebruikt om een lineair regressiemodel te fitten en de resultaten <strong>fit<\/strong> hebben genoemd.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Het volgende voorbeeld laat zien hoe u deze syntaxis in de praktijk kunt gebruiken.<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Gerelateerd:<\/strong> <a href=\"https:\/\/statorials.org\/nl\/extraheer-r-kwadraat-van-lm-naar-r\/\" target=\"_blank\" rel=\"noopener\">Hoe de R-kwadraat uit de functie lm() in R te extraheren<\/a><\/span><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Voorbeeld: Hoe residuen uit lm() in R te extraheren<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">Stel dat we het volgende dataframe in R hebben dat informatie bevat over de gespeelde minuten, het totaal aantal fouten en het totaal aantal punten gescoord door 10 basketbalspelers:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#create data frame\n<\/span>df &lt;- data. <span style=\"color: #3366ff;\">frame<\/span> (minutes=c(5, 10, 13, 14, 20, 22, 26, 34, 38, 40),\n                 fouls=c(5, 5, 3, 4, 2, 1, 3, 2, 1, 1),\n                 points=c(6, 8, 8, 7, 14, 10, 22, 24, 28, 30))\n\n<span style=\"color: #008080;\">#view data frame\n<\/span>df\n\n   minutes fouls points\n1 5 5 6\n2 10 5 8\n3 13 3 8\n4 14 4 7\n5 20 2 14\n6 22 1 10\n7 26 3 22\n8 34 2 24\n9 38 1 28\n10 40 1 30<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Stel dat we willen passen in het volgende meervoudige lineaire regressiemodel:<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>punten = \u03b2 <sub>0<\/sub> + \u03b2 <sub>1<\/sub> (minuten) + \u03b2 <sub>2<\/sub> (overtredingen)<\/strong><\/span><\/p>\n<p> <span style=\"color: #000000;\">We kunnen de functie <strong>lm()<\/strong> gebruiken om in dit regressiemodel te passen:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#fit multiple linear regression model\n<\/span>fit &lt;- lm(points ~ minutes + fouls, data=df)<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">We kunnen dan <strong>fit$residuals<\/strong> typen om de residuen uit het model te extraheren:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#extract residuals from model\n<\/span>fit$residuals\n\n         1 2 3 4 5 6 7 \n 2.0888729 -0.7982137 0.6371041 -3.5240982 1.9789676 -1.7920822 1.9306786 \n         8 9 10 \n-1.7048752 0.5692404 0.6144057<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Omdat er in totaal 10 waarnemingen in onze database zaten, zijn er 10 residuen \u2013 \u00e9\u00e9n voor elke waarneming.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Bijvoorbeeld:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\">De eerste waarneming heeft een residu van <strong>2.089<\/strong> .<\/span><\/li>\n<li> <span style=\"color: #000000;\">De tweede waarneming heeft een residu van <strong>-0,798<\/strong> .<\/span><\/li>\n<li> <span style=\"color: #000000;\">De derde waarneming heeft een residu van <strong>0,637<\/strong> .<\/span><\/li>\n<\/ul>\n<p> <span style=\"color: #000000;\">Enzovoort.<\/span><\/p>\n<p> <span style=\"color: #000000;\">We kunnen dan een grafiek maken van de residuen tegen de aangepaste waarden als we dat willen:<\/span> <\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><span style=\"color: #000000;\"><span style=\"color: #008080;\">#store residuals in variable\n<span style=\"color: #000000;\">res &lt;- fit$residuals<\/span>\n\n#produce residual vs. fitted plot\n<\/span>plot(fitted(fit), res)\n\n<span style=\"color: #008080;\">#add a horizontal line at 0 \n<\/span>abline(0,0)\n<\/span><\/span><\/strong><\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\" wp-image-33668 aligncenter\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/res1.jpg\" alt=\"\" width=\"462\" height=\"428\" srcset=\"\" sizes=\"auto, \"><\/p>\n<p> <span style=\"color: #000000;\">Op de x-as worden de gefitte waarden weergegeven en op de y-as de residuen.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Idealiter zouden de residuen willekeurig rond nul verspreid moeten zijn, zonder duidelijk patroon, om ervoor te zorgen dat aan de <a href=\"https:\/\/statorials.org\/nl\/regressie-van-heteroscedasticiteit\/\" target=\"_blank\" rel=\"noopener\">aanname van homoscedasticiteit<\/a> wordt voldaan.<\/span><\/p>\n<p> <span style=\"color: #000000;\">In de bovenstaande grafiek van de residuen kunnen we zien dat de residuen willekeurig rond nul verspreid lijken te zijn, zonder duidelijk patroon, wat betekent dat waarschijnlijk aan de aanname van homoscedasticiteit is voldaan.<\/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> <a href=\"https:\/\/statorials.org\/nl\/eenvoudige-lineaire-regressie-in-r\/\" target=\"_blank\" rel=\"noopener\">Hoe eenvoudige lineaire regressie uit te voeren in R<\/a><br \/> <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\/restspoor-r\/\" target=\"_blank\" rel=\"noopener\">Hoe maak je een restplot in R<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>U kunt de volgende syntaxis gebruiken om residuen uit de functie lm() in R te extraheren: fit$residuals In dit voorbeeld wordt ervan uitgegaan dat we de functie lm() hebben gebruikt om een lineair regressiemodel te fitten en de resultaten fit hebben genoemd. Het volgende voorbeeld laat zien hoe u deze syntaxis in de praktijk kunt [&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-4268","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 residuen uit de lm()-functie in R - Statorials te extraheren<\/title>\n<meta name=\"description\" content=\"In deze tutorial wordt aan de hand van een voorbeeld uitgelegd hoe u residuen uit de functie lm() in R kunt extraheren.\" \/>\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\/extraheer-de-residuen-van-lm-in-r\/\" \/>\n<meta property=\"og:locale\" content=\"de_DE\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Hoe residuen uit de lm()-functie in R - Statorials te extraheren\" \/>\n<meta property=\"og:description\" content=\"In deze tutorial wordt aan de hand van een voorbeeld uitgelegd hoe u residuen uit de functie lm() in R kunt extraheren.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/nl\/extraheer-de-residuen-van-lm-in-r\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-12T10:12:56+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/res1.jpg\" \/>\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\/extraheer-de-residuen-van-lm-in-r\/\",\"url\":\"https:\/\/statorials.org\/nl\/extraheer-de-residuen-van-lm-in-r\/\",\"name\":\"Hoe residuen uit de lm()-functie in R - Statorials te extraheren\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/nl\/#website\"},\"datePublished\":\"2023-07-12T10:12:56+00:00\",\"dateModified\":\"2023-07-12T10:12:56+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219\"},\"description\":\"In deze tutorial wordt aan de hand van een voorbeeld uitgelegd hoe u residuen uit de functie lm() in R kunt extraheren.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/nl\/extraheer-de-residuen-van-lm-in-r\/#breadcrumb\"},\"inLanguage\":\"de\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/nl\/extraheer-de-residuen-van-lm-in-r\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/nl\/extraheer-de-residuen-van-lm-in-r\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Thuis\",\"item\":\"https:\/\/statorials.org\/nl\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Hoe residuen uit de lm()-functie in r te extraheren\"}]},{\"@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 residuen uit de lm()-functie in R - Statorials te extraheren","description":"In deze tutorial wordt aan de hand van een voorbeeld uitgelegd hoe u residuen uit de functie lm() in R kunt extraheren.","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\/extraheer-de-residuen-van-lm-in-r\/","og_locale":"de_DE","og_type":"article","og_title":"Hoe residuen uit de lm()-functie in R - Statorials te extraheren","og_description":"In deze tutorial wordt aan de hand van een voorbeeld uitgelegd hoe u residuen uit de functie lm() in R kunt extraheren.","og_url":"https:\/\/statorials.org\/nl\/extraheer-de-residuen-van-lm-in-r\/","og_site_name":"Statorials","article_published_time":"2023-07-12T10:12:56+00:00","og_image":[{"url":"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/res1.jpg"}],"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\/extraheer-de-residuen-van-lm-in-r\/","url":"https:\/\/statorials.org\/nl\/extraheer-de-residuen-van-lm-in-r\/","name":"Hoe residuen uit de lm()-functie in R - Statorials te extraheren","isPartOf":{"@id":"https:\/\/statorials.org\/nl\/#website"},"datePublished":"2023-07-12T10:12:56+00:00","dateModified":"2023-07-12T10:12:56+00:00","author":{"@id":"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219"},"description":"In deze tutorial wordt aan de hand van een voorbeeld uitgelegd hoe u residuen uit de functie lm() in R kunt extraheren.","breadcrumb":{"@id":"https:\/\/statorials.org\/nl\/extraheer-de-residuen-van-lm-in-r\/#breadcrumb"},"inLanguage":"de","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/nl\/extraheer-de-residuen-van-lm-in-r\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/nl\/extraheer-de-residuen-van-lm-in-r\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Thuis","item":"https:\/\/statorials.org\/nl\/"},{"@type":"ListItem","position":2,"name":"Hoe residuen uit de lm()-functie in r te extraheren"}]},{"@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\/4268","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=4268"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/posts\/4268\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/media?parent=4268"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/categories?post=4268"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/tags?post=4268"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}