{"id":1977,"date":"2023-07-24T05:44:05","date_gmt":"2023-07-24T05:44:05","guid":{"rendered":"https:\/\/statorials.org\/nl\/lm-functie-in-r\/"},"modified":"2023-07-24T05:44:05","modified_gmt":"2023-07-24T05:44:05","slug":"lm-functie-in-r","status":"publish","type":"post","link":"https:\/\/statorials.org\/nl\/lm-functie-in-r\/","title":{"rendered":"Hoe de functie lm() in r te gebruiken om lineaire modellen te passen"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">De functie <strong>lm()<\/strong> in R wordt gebruikt om lineaire regressiemodellen aan te passen.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Deze functie gebruikt de volgende basissyntaxis:<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>lm(formule, gegevens, \u2026)<\/strong><\/span><\/p>\n<p> <span style=\"color: #000000;\">Goud:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\"><strong>formule:<\/strong> De lineaire modelformule (bijv. y ~ x1 + x2)<\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong>data:<\/strong> de naam van het datablok dat de gegevens bevat<\/span><\/li>\n<\/ul>\n<p> <span style=\"color: #000000;\">Het volgende voorbeeld laat zien hoe u deze functie in R kunt gebruiken om het volgende te doen:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\">Pas een regressiemodel toe<\/span><\/li>\n<li> <span style=\"color: #000000;\">Bekijk de samenvatting van de fit van het regressiemodel<\/span><\/li>\n<li> <span style=\"color: #000000;\">Bekijk modeldiagnostische plots<\/span><\/li>\n<li> <span style=\"color: #000000;\">Teken het gepaste regressiemodel<\/span><\/li>\n<li> <span style=\"color: #000000;\">Maak voorspellingen met behulp van het regressiemodel<\/span><\/li>\n<\/ul>\n<h3> <span style=\"color: #000000;\"><strong>Pas het regressiemodel aan<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">De volgende code laat zien hoe u de functie <strong>lm()<\/strong> gebruikt om een lineair regressiemodel in R te passen:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#define data<\/span>\ndf = data. <span style=\"color: #3366ff;\">frame<\/span> (x=c(1, 3, 3, 4, 5, 5, 6, 8, 9, 12),\n                y=c(12, 14, 14, 13, 17, 19, 22, 26, 24, 22))\n\n<span style=\"color: #008080;\">#fit linear regression model using 'x' as predictor and 'y' as response variable<\/span>\nmodel &lt;- lm(y ~ x, data=df)\n<\/strong><\/pre>\n<h3> <span style=\"color: #000000;\"><strong>Samenvatting van het regressiemodel weergeven<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">We kunnen vervolgens de functie <strong>summary()<\/strong> gebruiken om de samenvatting van de fit van het regressiemodel weer te geven:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#view summary of regression model<\/span>\nsummary(model)\n\nCall:\nlm(formula = y ~ x, data = df)\n\nResiduals:\n    Min 1Q Median 3Q Max \n-4.4793 -0.9772 -0.4772 1.4388 4.6328 \n\nCoefficients:\n            Estimate Std. Error t value Pr(&gt;|t|)    \n(Intercept) 11.1432 1.9104 5.833 0.00039 ***\nx 1.2780 0.2984 4.284 0.00267 ** \n---\nSignificant. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1\n\nResidual standard error: 2.929 on 8 degrees of freedom\nMultiple R-squared: 0.6964, Adjusted R-squared: 0.6584 \nF-statistic: 18.35 on 1 and 8 DF, p-value: 0.002675\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Zo interpreteert u de belangrijkste waarden in het model:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\"><strong>F-statistiek<\/strong> = 18,35, overeenkomstige <strong>p-waarde<\/strong> = 0,002675. Omdat deze p-waarde kleiner is dan 0,05 is het model als geheel statistisch significant.<\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong>Meerdere R kwadraat<\/strong> = 0,6964. Dit vertelt ons dat 69,64% van de variatie in de responsvariabele, y, kan worden verklaard door de voorspellende variabele, x.<\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong>Geschatte co\u00ebffici\u00ebnt van x<\/strong> : 1,2780. Dit vertelt ons dat elke extra eenheidstoename in x gepaard gaat met een gemiddelde toename van 1,2780 in y.<\/span><\/li>\n<\/ul>\n<p> <span style=\"color: #000000;\">We kunnen vervolgens de co\u00ebffici\u00ebntschattingen uit de uitvoer gebruiken om de geschatte regressievergelijking te schrijven:<\/span><\/p>\n<p> <span style=\"color: #000000;\">y = 11,1432 + 1,2780*(x)<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Bonus<\/strong> : u kunt <a href=\"https:\/\/statorials.org\/nl\/interpreteer-de-regressie-uitvoer-in-r\/\" target=\"_blank\" rel=\"noopener\">hier<\/a> een complete gids vinden voor het interpreteren van elke waarde van regressie-uitvoer in R.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Bekijk modeldiagnostische plots<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">We kunnen vervolgens de functie <strong>plot()<\/strong> gebruiken om de diagnostische plots van het regressiemodel te plotten:<\/span> <\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#create diagnostic plots\n<span style=\"color: #000000;\">plot(model)<\/span><\/span><\/strong> <\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\" wp-image-18677 aligncenter\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/lm2.png\" alt=\"\" width=\"653\" height=\"649\" srcset=\"\" sizes=\"auto, \"><\/p>\n<p> <span style=\"color: #000000;\">Met deze grafieken kunnen we de <a href=\"https:\/\/statorials.org\/nl\/residu\/\" target=\"_blank\" rel=\"noopener\">residuen<\/a> van het regressiemodel analyseren om te bepalen of het model geschikt is om voor de gegevens te gebruiken.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Raadpleeg <a href=\"https:\/\/statorials.org\/nl\/diagnostische-diagrammen-in-r\/\" target=\"_blank\" rel=\"noopener\">deze tutorial<\/a> voor een volledige uitleg over het interpreteren van de diagnostische plots van een model in R.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Teken het gepaste regressiemodel<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">We kunnen de functie <strong>abline()<\/strong> gebruiken om het gepaste regressiemodel te plotten:<\/span> <\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#create scatterplot of raw data<\/span>\nplot(df$x, df$y, col=' <span style=\"color: #ff0000;\">red<\/span> ', main=' <span style=\"color: #ff0000;\">Summary of Regression Model<\/span> ', xlab=' <span style=\"color: #ff0000;\">x<\/span> ', ylab=' <span style=\"color: #ff0000;\">y<\/span> ')\n\n<span style=\"color: #008080;\">#add fitted regression line\n<span style=\"color: #000000;\">abline(model)\n<\/span><\/span><\/strong><\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-18678\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/lm3.png\" alt=\"plot lm() in R\" width=\"448\" height=\"442\" srcset=\"\" sizes=\"auto, \"><\/p>\n<h3> <strong>Gebruik het regressiemodel om voorspellingen te doen<\/strong><\/h3>\n<p> <span style=\"color: #000000;\"><span style=\"color: #000000;\">We kunnen de functie <strong>voorspellen()<\/strong> gebruiken om de responswaarde voor een nieuwe waarneming te voorspellen:<\/span><\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><span style=\"color: #000000;\"><span style=\"color: #008080;\">#define new observation\n<\/span>new &lt;- data. <span style=\"color: #3366ff;\">frame<\/span> (x=c(5))\n\n<span style=\"color: #008080;\">#use the fitted model to predict the value for the new observation\n<\/span>predict(model, newdata = new)\n\n      1 \n17.5332<\/span>\n<\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Het model voorspelt dat deze nieuwe waarneming een responswaarde van <strong>17,5332<\/strong> zal hebben.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Aanvullende bronnen<\/strong><\/span><\/h3>\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\/stap-voor-stap-regressie-r\/\" target=\"_blank\" rel=\"noopener\">Hoe stapsgewijze regressie uit te voeren in R<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>De functie lm() in R wordt gebruikt om lineaire regressiemodellen aan te passen. Deze functie gebruikt de volgende basissyntaxis: lm(formule, gegevens, \u2026) Goud: formule: De lineaire modelformule (bijv. y ~ x1 + x2) data: de naam van het datablok dat de gegevens bevat Het volgende voorbeeld laat zien hoe u deze functie in R 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-1977","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 lm()-functie in R te gebruiken om lineaire modellen te passen - Statorials<\/title>\n<meta name=\"description\" content=\"In deze tutorial wordt uitgelegd hoe u de functie lm() in R kunt gebruiken om lineaire regressiemodellen te passen, met verschillende 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\/lm-functie-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 lm()-functie in R te gebruiken om lineaire modellen te passen - Statorials\" \/>\n<meta property=\"og:description\" content=\"In deze tutorial wordt uitgelegd hoe u de functie lm() in R kunt gebruiken om lineaire regressiemodellen te passen, met verschillende voorbeelden.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/nl\/lm-functie-in-r\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-24T05:44:05+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/lm2.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=\"3\u00a0Minuten\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/statorials.org\/nl\/lm-functie-in-r\/\",\"url\":\"https:\/\/statorials.org\/nl\/lm-functie-in-r\/\",\"name\":\"Hoe de lm()-functie in R te gebruiken om lineaire modellen te passen - Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/nl\/#website\"},\"datePublished\":\"2023-07-24T05:44:05+00:00\",\"dateModified\":\"2023-07-24T05:44:05+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219\"},\"description\":\"In deze tutorial wordt uitgelegd hoe u de functie lm() in R kunt gebruiken om lineaire regressiemodellen te passen, met verschillende voorbeelden.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/nl\/lm-functie-in-r\/#breadcrumb\"},\"inLanguage\":\"de\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/nl\/lm-functie-in-r\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/nl\/lm-functie-in-r\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Thuis\",\"item\":\"https:\/\/statorials.org\/nl\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Hoe de functie lm() in r te gebruiken om lineaire modellen te passen\"}]},{\"@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 lm()-functie in R te gebruiken om lineaire modellen te passen - Statorials","description":"In deze tutorial wordt uitgelegd hoe u de functie lm() in R kunt gebruiken om lineaire regressiemodellen te passen, met verschillende 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\/lm-functie-in-r\/","og_locale":"de_DE","og_type":"article","og_title":"Hoe de lm()-functie in R te gebruiken om lineaire modellen te passen - Statorials","og_description":"In deze tutorial wordt uitgelegd hoe u de functie lm() in R kunt gebruiken om lineaire regressiemodellen te passen, met verschillende voorbeelden.","og_url":"https:\/\/statorials.org\/nl\/lm-functie-in-r\/","og_site_name":"Statorials","article_published_time":"2023-07-24T05:44:05+00:00","og_image":[{"url":"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/lm2.png"}],"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\/lm-functie-in-r\/","url":"https:\/\/statorials.org\/nl\/lm-functie-in-r\/","name":"Hoe de lm()-functie in R te gebruiken om lineaire modellen te passen - Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/nl\/#website"},"datePublished":"2023-07-24T05:44:05+00:00","dateModified":"2023-07-24T05:44:05+00:00","author":{"@id":"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219"},"description":"In deze tutorial wordt uitgelegd hoe u de functie lm() in R kunt gebruiken om lineaire regressiemodellen te passen, met verschillende voorbeelden.","breadcrumb":{"@id":"https:\/\/statorials.org\/nl\/lm-functie-in-r\/#breadcrumb"},"inLanguage":"de","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/nl\/lm-functie-in-r\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/nl\/lm-functie-in-r\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Thuis","item":"https:\/\/statorials.org\/nl\/"},{"@type":"ListItem","position":2,"name":"Hoe de functie lm() in r te gebruiken om lineaire modellen te passen"}]},{"@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\/1977","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=1977"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/posts\/1977\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/media?parent=1977"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/categories?post=1977"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/tags?post=1977"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}