{"id":3469,"date":"2023-07-17T08:05:49","date_gmt":"2023-07-17T08:05:49","guid":{"rendered":"https:\/\/statorials.org\/nl\/r-lineaire-regressie-met-categorische-variabelen\/"},"modified":"2023-07-17T08:05:49","modified_gmt":"2023-07-17T08:05:49","slug":"r-lineaire-regressie-met-categorische-variabelen","status":"publish","type":"post","link":"https:\/\/statorials.org\/nl\/r-lineaire-regressie-met-categorische-variabelen\/","title":{"rendered":"Hoe lineaire regressie uit te voeren met categorische variabelen in r"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">Lineaire regressie is een methode die we kunnen gebruiken om de relatie tussen een of meer voorspellende variabelen en een<a href=\"https:\/\/statorials.org\/nl\/variabelen-verklarende-reacties\/\" target=\"_blank\" rel=\"noopener\">responsvariabele<\/a> te kwantificeren.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Vaak wilt u misschien een regressiemodel passen met een of meer<a href=\"https:\/\/statorials.org\/nl\/categorisch-versus-kwantitatief\/\" target=\"_blank\" rel=\"noopener\">categorische variabelen<\/a> als voorspellende variabelen.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Deze tutorial biedt een stapsgewijs voorbeeld van hoe u lineaire regressie kunt uitvoeren met categorische variabelen in R.<\/span><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Voorbeeld: lineaire regressie met categorische variabelen in R<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">Stel dat we het volgende dataframe in R hebben dat informatie bevat over drie variabelen voor 12 verschillende basketbalspelers:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\">punten gescoord<\/span><\/li>\n<li> <span style=\"color: #000000;\">uren besteed aan oefenen<\/span><\/li>\n<li> <span style=\"color: #000000;\">trainingsprogramma gebruikt<\/span><\/li>\n<\/ul>\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> (points=c(7, 7, 9, 10, 13, 14, 12, 10, 16, 19, 22, 18),\n                 hours=c(1, 2, 2, 3, 2, 6, 4, 3, 4, 5, 8, 6),\n                 program=c(1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3))\n\n<span style=\"color: #008080;\">#view data frame\n<\/span>df\n\n   points hours program\n1 7 1 1\n2 7 2 1\n3 9 2 1\n4 10 3 1\n5 13 2 2\n6 14 6 2\n7 12 4 2\n8 10 3 2\n9 16 4 3\n10 19 5 3\n11 22 8 3\n12 18 6 3<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Stel dat we aan het volgende lineaire regressiemodel willen voldoen:<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>punten = \u03b2 <sub>0<\/sub> + \u03b2 <sub>1<\/sub> uur + \u03b2 <sub>2<\/sub> programma<\/strong><\/span><\/p>\n<p> <span style=\"color: #000000;\">In dit voorbeeld zijn uren een continue variabele, maar programma is een <strong>categorische variabele<\/strong> die drie mogelijke categorie\u00ebn kan aannemen: programma 1, programma 2 of programma 3.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Om aan dit regressiemodel te voldoen en R te vertellen dat de variabele &#8222;programma&#8220; een categorische variabele is, moeten we <strong>as.factor()<\/strong> gebruiken om deze naar een factor te converteren en vervolgens het model aanpassen:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#convert 'program' to factor\n<span style=\"color: #000000;\">df$program &lt;- as. <span style=\"color: #3366ff;\">factor<\/span> (df$program)\n<\/span>\n#fit linear regression model\n<span style=\"color: #000000;\">fit &lt;- lm(points ~ hours + program, data = df)\n<\/span>\n#view model summary\n<span style=\"color: #000000;\">summary(fit)\n\nCall:\nlm(formula = points ~ hours + program, data = df)\n\nResiduals:\n    Min 1Q Median 3Q Max \n-1.5192 -1.0064 -0.3590 0.8269 2.4551 \n\nCoefficients:\n            Estimate Std. Error t value Pr(&gt;|t|)    \n(Intercept) 6.3013 0.9462 6.660 0.000159 ***\nhours 0.9744 0.3176 3.068 0.015401 *  \nprogram2 2.2949 1.1369 2.019 0.078234 .  \nprogram3 6.8462 1.5499 4.417 0.002235 ** \n---\nSignificant. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1\n\nResidual standard error: 1.403 on 8 degrees of freedom\nMultiple R-squared: 0.9392, Adjusted R-squared: 0.9164 \nF-statistic: 41.21 on 3 and 8 DF, p-value: 3.276e-05<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Uit de waarden in de kolom <strong>Schatting<\/strong> kunnen we het gepaste regressiemodel schrijven:<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>punten = 6,3013 + 0,9744 (uren) + 2,2949 (programma 2) + 6,8462 (programma 3)<\/strong><\/span><\/p>\n<p> <span style=\"color: #000000;\">Hier leest u hoe u de co\u00ebffici\u00ebntwaarden in het resultaat interpreteert:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\"><strong>Uren<\/strong> : voor elk extra uur dat wordt besteed aan oefenen, stijgen de gescoorde punten met gemiddeld <strong>0,9744,<\/strong> ervan uitgaande dat het programma constant blijft.<\/span>\n<ul>\n<li> <span style=\"color: #000000;\">De p-waarde is 0,015, wat aangeeft dat de uren besteed aan oefenen een statistisch significante voorspeller zijn van punten gescoord op het \u03b1 = 0,05-niveau.<\/span><\/li>\n<\/ul>\n<\/li>\n<li> <span style=\"color: #000000;\"><strong>schema2<\/strong> : Spelers die schema 2 gebruikten scoorden gemiddeld <strong>2,2949<\/strong> punten meer dan spelers die schema 1 gebruikten, ervan uitgaande dat de uren constant blijven.<\/span>\n<ul>\n<li> <span style=\"color: #000000;\">De p-waarde is 0,078, wat aangeeft dat er geen statistisch significant verschil is in de punten die worden gescoord door spelers die programma 2 hebben gebruikt in vergelijking met spelers die programma 1 hebben gebruikt, op niveau \u03b1 = 0,05.<\/span><\/li>\n<\/ul>\n<\/li>\n<li> <span style=\"color: #000000;\"><strong>schema3<\/strong> : Spelers die schema 3 gebruikten scoorden gemiddeld <strong>2,2949<\/strong> punten meer dan spelers die schema 1 gebruikten, ervan uitgaande dat de uren constant blijven.<\/span>\n<ul>\n<li> <span style=\"color: #000000;\">De p-waarde is 0,002, wat aangeeft dat er een statistisch significant verschil is in de punten die worden gescoord door spelers die schema 3 gebruikten in vergelijking met spelers die schema 1 gebruikten, op het \u03b1 = 0,05-niveau.<\/span><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p> <span style=\"color: #000000;\">Met behulp van het gepaste regressiemodel kunnen we het aantal punten voorspellen dat een speler scoort op basis van het totaal aantal uren training en het programma dat hij heeft gebruikt.<\/span><\/p>\n<p> <span style=\"color: #000000;\">We kunnen bijvoorbeeld de volgende code gebruiken om de punten te voorspellen die zijn gescoord door een speler die 5 uur heeft getraind en trainingsschema 3 heeft gebruikt:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#define new player\n<\/span>new &lt;- data. <span style=\"color: #3366ff;\">frame<\/span> (hours=c(5), program=as. <span style=\"color: #3366ff;\">factor<\/span> (c(3)))\n\n<span style=\"color: #008080;\">#use the fitted model to predict the points for the new player\n<\/span>predict(fit, newdata=new)\n\n       1 \n18.01923 \n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Het model voorspelt dat deze nieuwe speler <strong>18,01923<\/strong> punten zal scoren.<\/span><\/p>\n<p> <span style=\"color: #000000;\">We kunnen bevestigen dat dit correct is door de waarden van de nieuwe speler in de aangepaste regressievergelijking in te voegen:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\">punten = 6,3013 + 0,9744 (uren) + 2,2949 (programma 2) + 6,8462 (programma 3)<\/span><\/li>\n<li> <span style=\"color: #000000;\">punten = 6,3013 + 0,9744(5) + 2,2949(0) + 6,8462(1)<\/span><\/li>\n<li> <span style=\"color: #000000;\">punten = 18.019<\/span><\/li>\n<\/ul>\n<p> <span style=\"color: #000000;\">Dit komt overeen met de waarde die we hebben berekend met de functie <strong>voorspellen()<\/strong> in R.<\/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>Lineaire regressie is een methode die we kunnen gebruiken om de relatie tussen een of meer voorspellende variabelen en eenresponsvariabele te kwantificeren. Vaak wilt u misschien een regressiemodel passen met een of meercategorische variabelen als voorspellende variabelen. Deze tutorial biedt een stapsgewijs voorbeeld van hoe u lineaire regressie kunt uitvoeren met categorische variabelen in R. [&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-3469","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 lineaire regressie uit te voeren met categorische variabelen in R - Statorials<\/title>\n<meta name=\"description\" content=\"In deze tutorial wordt uitgelegd hoe u lineaire regressie uitvoert met categorische variabelen in R, inclusief een compleet 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\/r-lineaire-regressie-met-categorische-variabelen\/\" \/>\n<meta property=\"og:locale\" content=\"de_DE\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Hoe lineaire regressie uit te voeren met categorische variabelen in R - Statorials\" \/>\n<meta property=\"og:description\" content=\"In deze tutorial wordt uitgelegd hoe u lineaire regressie uitvoert met categorische variabelen in R, inclusief een compleet voorbeeld.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/nl\/r-lineaire-regressie-met-categorische-variabelen\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-17T08:05:49+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\/r-lineaire-regressie-met-categorische-variabelen\/\",\"url\":\"https:\/\/statorials.org\/nl\/r-lineaire-regressie-met-categorische-variabelen\/\",\"name\":\"Hoe lineaire regressie uit te voeren met categorische variabelen in R - Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/nl\/#website\"},\"datePublished\":\"2023-07-17T08:05:49+00:00\",\"dateModified\":\"2023-07-17T08:05:49+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219\"},\"description\":\"In deze tutorial wordt uitgelegd hoe u lineaire regressie uitvoert met categorische variabelen in R, inclusief een compleet voorbeeld.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/nl\/r-lineaire-regressie-met-categorische-variabelen\/#breadcrumb\"},\"inLanguage\":\"de\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/nl\/r-lineaire-regressie-met-categorische-variabelen\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/nl\/r-lineaire-regressie-met-categorische-variabelen\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Thuis\",\"item\":\"https:\/\/statorials.org\/nl\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Hoe lineaire regressie uit te voeren met categorische variabelen in r\"}]},{\"@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 lineaire regressie uit te voeren met categorische variabelen in R - Statorials","description":"In deze tutorial wordt uitgelegd hoe u lineaire regressie uitvoert met categorische variabelen in R, inclusief een compleet 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\/r-lineaire-regressie-met-categorische-variabelen\/","og_locale":"de_DE","og_type":"article","og_title":"Hoe lineaire regressie uit te voeren met categorische variabelen in R - Statorials","og_description":"In deze tutorial wordt uitgelegd hoe u lineaire regressie uitvoert met categorische variabelen in R, inclusief een compleet voorbeeld.","og_url":"https:\/\/statorials.org\/nl\/r-lineaire-regressie-met-categorische-variabelen\/","og_site_name":"Statorials","article_published_time":"2023-07-17T08:05:49+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\/r-lineaire-regressie-met-categorische-variabelen\/","url":"https:\/\/statorials.org\/nl\/r-lineaire-regressie-met-categorische-variabelen\/","name":"Hoe lineaire regressie uit te voeren met categorische variabelen in R - Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/nl\/#website"},"datePublished":"2023-07-17T08:05:49+00:00","dateModified":"2023-07-17T08:05:49+00:00","author":{"@id":"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219"},"description":"In deze tutorial wordt uitgelegd hoe u lineaire regressie uitvoert met categorische variabelen in R, inclusief een compleet voorbeeld.","breadcrumb":{"@id":"https:\/\/statorials.org\/nl\/r-lineaire-regressie-met-categorische-variabelen\/#breadcrumb"},"inLanguage":"de","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/nl\/r-lineaire-regressie-met-categorische-variabelen\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/nl\/r-lineaire-regressie-met-categorische-variabelen\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Thuis","item":"https:\/\/statorials.org\/nl\/"},{"@type":"ListItem","position":2,"name":"Hoe lineaire regressie uit te voeren met categorische variabelen in r"}]},{"@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\/3469","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=3469"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/posts\/3469\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/media?parent=3469"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/categories?post=3469"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/tags?post=3469"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}