{"id":3905,"date":"2023-07-14T20:50:46","date_gmt":"2023-07-14T20:50:46","guid":{"rendered":"https:\/\/statorials.org\/it\/ipotesi-lineare-r\/"},"modified":"2023-07-14T20:50:46","modified_gmt":"2023-07-14T20:50:46","slug":"ipotesi-lineare-r","status":"publish","type":"post","link":"https:\/\/statorials.org\/it\/ipotesi-lineare-r\/","title":{"rendered":"Come utilizzare la funzione linearhypothesis() in r"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">\u00c8 possibile utilizzare la funzione <strong>LinearHypothesis()<\/strong> del pacchetto <strong>auto<\/strong> in R per testare ipotesi lineari in un modello di regressione specifico.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Questa funzione utilizza la seguente sintassi di base:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>linearHypothesis(fit, c(\" <span style=\"color: #ff0000;\">var1=0<\/span> \", \" <span style=\"color: #ff0000;\">var2=0<\/span> \"))<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Questo particolare esempio verifica se i coefficienti di regressione <strong>var1<\/strong> e <strong>var2<\/strong> nel modello chiamato <strong>fit<\/strong> sono congiuntamente uguali a zero.<\/span><\/p>\n<p> <span style=\"color: #000000;\">L&#8217;esempio seguente mostra come utilizzare questa funzione nella pratica.<\/span><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Esempio: come utilizzare la funzione LinearHypothesis() in R<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">Supponiamo di avere il seguente frame di dati in R che mostra il numero di ore trascorse a studiare, il numero di esami pratici sostenuti e il punteggio dell&#8217;esame finale di 10 studenti in una classe:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#create data frame\n<\/span>df &lt;- data.frame(score=c(77, 79, 84, 85, 88, 99, 95, 90, 92, 94),\n                 hours=c(1, 1, 2, 3, 2, 4, 4, 2, 3, 3),\n                 prac_exams=c(2, 4, 4, 2, 4, 5, 4, 3, 2, 1))\n\n<span style=\"color: #008080;\">#view data frame\n<\/span>df\n\n   score hours prac_exams\n1 77 1 2\n2 79 1 4\n3 84 2 4\n4 85 3 2\n5 88 2 4\n6 99 4 5\n7 95 4 4\n8 90 2 3\n9 92 3 2\n10 94 3 1\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Supponiamo ora di voler adattare il seguente modello di regressione lineare multipla in R:<\/span><\/p>\n<p> <span style=\"color: #000000;\">Punteggio esame = \u03b2 <sub>0<\/sub> + \u03b2 <sub>1<\/sub> (ore) + \u03b2 <sub>2<\/sub> (esami pratici)<\/span><\/p>\n<p> <span style=\"color: #000000;\">Possiamo usare la funzione <a href=\"https:\/\/statorials.org\/it\/funzione-lm-in-r\/\" target=\"_blank\" rel=\"noopener\">lm()<\/a> per adattare questo modello:<\/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(score ~ hours + prac_exams, data=df)\n\n<span style=\"color: #008080;\">#view summary of model\n<\/span>summary(fit)\n\nCall:\nlm(formula = score ~ hours + prac_exams, data = df)\n\nResiduals:\n    Min 1Q Median 3Q Max \n-5.8366 -2.0875 0.1381 2.0652 4.6381 \n\nCoefficients:\n            Estimate Std. Error t value Pr(&gt;|t|)    \n(Intercept) 72.7393 3.9455 18.436 3.42e-07 ***\nhours 5.8093 1.1161 5.205 0.00125 ** \nprac_exams 0.3346 0.9369 0.357 0.73150    \n---\nSignificant. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1\n\nResidual standard error: 3.59 on 7 degrees of freedom\nMultiple R-squared: 0.8004, Adjusted R-squared: 0.7434 \nF-statistic: 14.03 on 2 and 7 DF, p-value: 0.003553\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Supponiamo ora di voler verificare se il coefficiente <strong>orario<\/strong> e <strong>prac_exams<\/strong> sono entrambi zero.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Possiamo usare la funzione <strong>LinearHypothesis()<\/strong> per fare questo:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008000;\">library<\/span> (car)\n\n<span style=\"color: #008080;\">#perform hypothesis test for hours=0 and prac_exams=0\n<\/span>linearHypothesis(fit, c(\" <span style=\"color: #ff0000;\">hours=0<\/span> \", \" <span style=\"color: #ff0000;\">prac_exams=0<\/span> \"))\n\nLinear hypothesis testing\n\nHypothesis:\nhours = 0\nprac_exams = 0\n\nModel 1: restricted model\nModel 2: score ~ hours + prac_exams\n\n  Res.Df RSS Df Sum of Sq F Pr(&gt;F)   \n1 9 452.10                                \n2 7 90.24 2 361.86 14.035 0.003553 **\n---\nSignificant. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Il test delle ipotesi restituisce i seguenti valori:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\"><strong>Statistica del test F<\/strong> : 14.035<\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong>Valore p<\/strong> : 0,003553<\/span><\/li>\n<\/ul>\n<p> <span style=\"color: #000000;\">Questo particolare test di ipotesi utilizza le seguenti ipotesi nulle e alternative:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\"><strong>H <sub>0<\/sub><\/strong> : Entrambi i coefficienti di regressione sono uguali a zero.<\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong>H <sub>A<\/sub><\/strong> : Almeno un coefficiente di regressione non \u00e8 uguale a zero.<\/span><\/li>\n<\/ul>\n<p> <span style=\"color: #000000;\">Poich\u00e9 il valore p del test (0,003553) \u00e8 inferiore a 0,05, rifiutiamo l&#8217;ipotesi nulla.<\/span><\/p>\n<p> <span style=\"color: #000000;\">In altre parole, non abbiamo prove sufficienti per affermare che i coefficienti di regressione per <strong>ore<\/strong> e <strong>prac_exams<\/strong> siano entrambi uguali a zero.<\/span><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Risorse addizionali<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">Le esercitazioni seguenti forniscono informazioni aggiuntive sulla regressione lineare in R:<\/span><\/p>\n<p> <a href=\"https:\/\/statorials.org\/it\/interpretare-loutput-della-regressione-in-r\/\" target=\"_blank\" rel=\"noopener\">Come interpretare l&#8217;output della regressione in R<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/regressione-lineare-semplice-in-r\/\" target=\"_blank\" rel=\"noopener\">Come eseguire una regressione lineare semplice in R<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/regressione-lineare-multipla-r\/\" target=\"_blank\" rel=\"noopener\">Come eseguire la regressione lineare multipla in R<\/a><br \/> Come eseguire la regressione logistica in R<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u00c8 possibile utilizzare la funzione LinearHypothesis() del pacchetto auto in R per testare ipotesi lineari in un modello di regressione specifico. Questa funzione utilizza la seguente sintassi di base: linearHypothesis(fit, c(&#8221; var1=0 &#8220;, &#8221; var2=0 &#8220;)) Questo particolare esempio verifica se i coefficienti di regressione var1 e var2 nel modello chiamato fit sono congiuntamente uguali [&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":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Come utilizzare la funzione LinearHypothesis() in R - Stology<\/title>\n<meta name=\"description\" content=\"Questo tutorial spiega come utilizzare la funzione LinearHypothesis() in R per testare ipotesi lineari su modelli di regressione.\" \/>\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\/it\/ipotesi-lineare-r\/\" \/>\n<meta property=\"og:locale\" content=\"it_IT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Come utilizzare la funzione LinearHypothesis() in R - Stology\" \/>\n<meta property=\"og:description\" content=\"Questo tutorial spiega come utilizzare la funzione LinearHypothesis() in R per testare ipotesi lineari su modelli di regressione.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/it\/ipotesi-lineare-r\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-14T20:50:46+00:00\" \/>\n<meta name=\"author\" content=\"Benjamin anderson\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Benjamin anderson\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minuti\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/statorials.org\/it\/ipotesi-lineare-r\/\",\"url\":\"https:\/\/statorials.org\/it\/ipotesi-lineare-r\/\",\"name\":\"Come utilizzare la funzione LinearHypothesis() in R - Stology\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/it\/#website\"},\"datePublished\":\"2023-07-14T20:50:46+00:00\",\"dateModified\":\"2023-07-14T20:50:46+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae\"},\"description\":\"Questo tutorial spiega come utilizzare la funzione LinearHypothesis() in R per testare ipotesi lineari su modelli di regressione.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/it\/ipotesi-lineare-r\/#breadcrumb\"},\"inLanguage\":\"it-IT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/it\/ipotesi-lineare-r\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/it\/ipotesi-lineare-r\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Casa\",\"item\":\"https:\/\/statorials.org\/it\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Come utilizzare la funzione linearhypothesis() in r\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/statorials.org\/it\/#website\",\"url\":\"https:\/\/statorials.org\/it\/\",\"name\":\"Statorials\",\"description\":\"La tua guida all&#039;alfabetizzazione statistica!\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/statorials.org\/it\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"it-IT\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae\",\"name\":\"Benjamin anderson\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"it-IT\",\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/statorials.org\/it\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"contentUrl\":\"https:\/\/statorials.org\/it\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"caption\":\"Benjamin anderson\"},\"description\":\"Ciao, sono Benjamin, un professore di statistica in pensione diventato insegnante dedicato di Statorials. Con una vasta esperienza e competenza nel campo della statistica, sono ansioso di condividere le mie conoscenze per potenziare gli studenti attraverso Statorials. Scopri di pi\u00f9\",\"sameAs\":[\"https:\/\/statorials.org\/it\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Come utilizzare la funzione LinearHypothesis() in R - Stology","description":"Questo tutorial spiega come utilizzare la funzione LinearHypothesis() in R per testare ipotesi lineari su modelli di regressione.","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\/it\/ipotesi-lineare-r\/","og_locale":"it_IT","og_type":"article","og_title":"Come utilizzare la funzione LinearHypothesis() in R - Stology","og_description":"Questo tutorial spiega come utilizzare la funzione LinearHypothesis() in R per testare ipotesi lineari su modelli di regressione.","og_url":"https:\/\/statorials.org\/it\/ipotesi-lineare-r\/","og_site_name":"Statorials","article_published_time":"2023-07-14T20:50:46+00:00","author":"Benjamin anderson","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Benjamin anderson","Est. reading time":"2 minuti"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/statorials.org\/it\/ipotesi-lineare-r\/","url":"https:\/\/statorials.org\/it\/ipotesi-lineare-r\/","name":"Come utilizzare la funzione LinearHypothesis() in R - Stology","isPartOf":{"@id":"https:\/\/statorials.org\/it\/#website"},"datePublished":"2023-07-14T20:50:46+00:00","dateModified":"2023-07-14T20:50:46+00:00","author":{"@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae"},"description":"Questo tutorial spiega come utilizzare la funzione LinearHypothesis() in R per testare ipotesi lineari su modelli di regressione.","breadcrumb":{"@id":"https:\/\/statorials.org\/it\/ipotesi-lineare-r\/#breadcrumb"},"inLanguage":"it-IT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/it\/ipotesi-lineare-r\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/it\/ipotesi-lineare-r\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Casa","item":"https:\/\/statorials.org\/it\/"},{"@type":"ListItem","position":2,"name":"Come utilizzare la funzione linearhypothesis() in r"}]},{"@type":"WebSite","@id":"https:\/\/statorials.org\/it\/#website","url":"https:\/\/statorials.org\/it\/","name":"Statorials","description":"La tua guida all&#039;alfabetizzazione statistica!","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/statorials.org\/it\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"it-IT"},{"@type":"Person","@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae","name":"Benjamin anderson","image":{"@type":"ImageObject","inLanguage":"it-IT","@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/image\/","url":"https:\/\/statorials.org\/it\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","contentUrl":"https:\/\/statorials.org\/it\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","caption":"Benjamin anderson"},"description":"Ciao, sono Benjamin, un professore di statistica in pensione diventato insegnante dedicato di Statorials. Con una vasta esperienza e competenza nel campo della statistica, sono ansioso di condividere le mie conoscenze per potenziare gli studenti attraverso Statorials. Scopri di pi\u00f9","sameAs":["https:\/\/statorials.org\/it"]}]}},"yoast_meta":{"yoast_wpseo_title":"","yoast_wpseo_metadesc":"","yoast_wpseo_canonical":""},"_links":{"self":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts\/3905"}],"collection":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/comments?post=3905"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts\/3905\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/media?parent=3905"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/categories?post=3905"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/tags?post=3905"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}