{"id":2660,"date":"2023-07-21T07:21:55","date_gmt":"2023-07-21T07:21:55","guid":{"rendered":"https:\/\/statorials.org\/it\/test-kpss-in-r\/"},"modified":"2023-07-21T07:21:55","modified_gmt":"2023-07-21T07:21:55","slug":"test-kpss-in-r","status":"publish","type":"post","link":"https:\/\/statorials.org\/it\/test-kpss-in-r\/","title":{"rendered":"Come eseguire un test kpss in r (incluso un esempio)"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">Un <strong>test KPSS<\/strong> pu\u00f2 essere utilizzato per determinare se una serie temporale ha un trend stazionario.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Questo test utilizza la seguente ipotesi nulla e alternativa:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\"><strong>H <sub>0<\/sub><\/strong> : La serie storica ha un andamento stazionario.<\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong>H <sub>A<\/sub><\/strong> : La serie storica <em>non ha<\/em> un andamento stazionario.<\/span><\/li>\n<\/ul>\n<p> <span style=\"color: #000000;\">Se il <a href=\"https:\/\/statorials.org\/it\/valori-p-significativita-statistica\/\" target=\"_blank\" rel=\"noopener\">p-value<\/a> del test \u00e8 inferiore ad un certo livello di significativit\u00e0 (es. \u03b1 = 0,05), allora rifiutiamo l&#8217;ipotesi nulla e concludiamo che la serie storica non ha un trend stazionario.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Altrimenti non riusciremo a rifiutare l\u2019ipotesi nulla.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Gli esempi seguenti mostrano come eseguire un test KPSS in R.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Esempio 1: test KPSS in R (con dati stazionari)<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Innanzitutto, creiamo alcuni dati falsi in R con cui lavorare:<\/span> <\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#make this example reproducible\n<span style=\"color: #000000;\">set. <span style=\"color: #3366ff;\">seeds<\/span> (100)\n\n<span style=\"color: #008080;\">#create time series data\n<\/span>data&lt;-rnorm(100)\n\n<span style=\"color: #008080;\">#plot time series data as line plot\n<\/span>plot(data, type=' <span style=\"color: #ff0000;\">l<\/span> ')<\/span><\/span><\/strong> <\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\" wp-image-23441 aligncenter\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/kpss1.jpg\" alt=\"\" width=\"441\" height=\"404\" srcset=\"\" sizes=\"\"><\/p>\n<p> <span style=\"color: #000000;\">Possiamo utilizzare la funzione <strong>kpss.test()<\/strong> dal pacchetto <strong>tseries<\/strong> per eseguire un test KPSS sui dati di queste serie temporali:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008000;\">library<\/span> (tseries)\n\n<span style=\"color: #008080;\">#perform KPSS test<\/span>\nkpss. <span style=\"color: #3366ff;\">test<\/span> (data, null=\" <span style=\"color: #008000;\">Trend<\/span> \")\n\n\tKPSS Test for Trend Stationarity\n\ndata:data\nKPSS Trend = 0.034563, Truncation lag parameter = 4, p-value = 0.1\n\nWarning message:\nIn kpss.test(data, null = \"Trend\"): p-value greater than printed p-value\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Il valore p \u00e8 <strong>0,1<\/strong> . Poich\u00e9 questo valore non \u00e8 inferiore a 0,05, non riusciamo a rifiutare l&#8217;ipotesi nulla del test KPSS.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Ci\u00f2 significa che possiamo assumere che la serie storica abbia un andamento stazionario.<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Nota<\/strong> : il valore p in realt\u00e0 \u00e8 ancora maggiore di 0,1, ma il valore pi\u00f9 basso prodotto dalla funzione kpss.test() \u00e8 0,1.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Esempio 2: test KPSS in R (con dati non stazionari)<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Innanzitutto, creiamo alcuni dati falsi in R con cui lavorare:<\/span> <\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#make this example reproducible<span style=\"color: #000000;\">\n\n<span style=\"color: #008080;\">#create time series data\n<\/span>data &lt;-c(0, 3, 4, 3, 6, 7, 5, 8, 15, 13, 19, 12, 29, 15, 45, 23, 67, 45)\n\n<span style=\"color: #008080;\">#plot time series data as line plot\n<\/span>plot(data, type=' <span style=\"color: #ff0000;\">l<\/span> ')<\/span><\/span><\/strong> <\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\" wp-image-23443 aligncenter\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/kpss2.jpg\" alt=\"\" width=\"408\" height=\"369\" srcset=\"\" sizes=\"\"><\/p>\n<p> <span style=\"color: #000000;\">Ancora una volta, possiamo utilizzare la funzione <strong>kpss.test()<\/strong> del pacchetto <strong>tseries<\/strong> per eseguire un test KPSS sui dati di questa serie temporale:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008000;\">library<\/span> (tseries)\n\n<span style=\"color: #008080;\">#perform KPSS test<\/span>\nkpss. <span style=\"color: #3366ff;\">test<\/span> (data, null=\" <span style=\"color: #008000;\">Trend<\/span> \")\n\n\tKPSS Test for Trend Stationarity\n\ndata:data\nKPSS Trend = 0.149, Truncation lag parameter = 2, p-value = 0.04751<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Il valore p \u00e8 <strong>0,04751<\/strong> . Essendo questo valore inferiore a 0,05, rifiutiamo l&#8217;ipotesi nulla del test KPSS.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Ci\u00f2 significa che la serie storica <em>non \u00e8<\/em> stazionaria.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Risorse addizionali<\/strong><\/span><span style=\"color: #000000;\"><br \/><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Le esercitazioni seguenti forniscono informazioni aggiuntive su come utilizzare i dati delle serie temporali in R:<\/span><\/p>\n<p> <a href=\"https:\/\/statorials.org\/it\/tracciare-le-serie-temporali-in-r\/\" target=\"_blank\" rel=\"noopener\">Come tracciare una serie temporale in R<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/test-dickey-fuller-in-r\/\" target=\"_blank\" rel=\"noopener\">Come eseguire un test Dickey-Fuller aumentato in R<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Un test KPSS pu\u00f2 essere utilizzato per determinare se una serie temporale ha un trend stazionario. Questo test utilizza la seguente ipotesi nulla e alternativa: H 0 : La serie storica ha un andamento stazionario. H A : La serie storica non ha un andamento stazionario. Se il p-value del test \u00e8 inferiore ad un [&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 eseguire un test KPSS in R (con esempio) - Statorials<\/title>\n<meta name=\"description\" content=\"Questo tutorial spiega come eseguire un test KPSS in R, con un esempio completo.\" \/>\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\/test-kpss-in-r\/\" \/>\n<meta property=\"og:locale\" content=\"it_IT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Come eseguire un test KPSS in R (con esempio) - Statorials\" \/>\n<meta property=\"og:description\" content=\"Questo tutorial spiega come eseguire un test KPSS in R, con un esempio completo.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/it\/test-kpss-in-r\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-21T07:21:55+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/kpss1.jpg\" \/>\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\/test-kpss-in-r\/\",\"url\":\"https:\/\/statorials.org\/it\/test-kpss-in-r\/\",\"name\":\"Come eseguire un test KPSS in R (con esempio) - Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/it\/#website\"},\"datePublished\":\"2023-07-21T07:21:55+00:00\",\"dateModified\":\"2023-07-21T07:21:55+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae\"},\"description\":\"Questo tutorial spiega come eseguire un test KPSS in R, con un esempio completo.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/it\/test-kpss-in-r\/#breadcrumb\"},\"inLanguage\":\"it-IT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/it\/test-kpss-in-r\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/it\/test-kpss-in-r\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Casa\",\"item\":\"https:\/\/statorials.org\/it\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Come eseguire un test kpss in r (incluso un esempio)\"}]},{\"@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 eseguire un test KPSS in R (con esempio) - Statorials","description":"Questo tutorial spiega come eseguire un test KPSS in R, con un esempio completo.","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\/test-kpss-in-r\/","og_locale":"it_IT","og_type":"article","og_title":"Come eseguire un test KPSS in R (con esempio) - Statorials","og_description":"Questo tutorial spiega come eseguire un test KPSS in R, con un esempio completo.","og_url":"https:\/\/statorials.org\/it\/test-kpss-in-r\/","og_site_name":"Statorials","article_published_time":"2023-07-21T07:21:55+00:00","og_image":[{"url":"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/kpss1.jpg"}],"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\/test-kpss-in-r\/","url":"https:\/\/statorials.org\/it\/test-kpss-in-r\/","name":"Come eseguire un test KPSS in R (con esempio) - Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/it\/#website"},"datePublished":"2023-07-21T07:21:55+00:00","dateModified":"2023-07-21T07:21:55+00:00","author":{"@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae"},"description":"Questo tutorial spiega come eseguire un test KPSS in R, con un esempio completo.","breadcrumb":{"@id":"https:\/\/statorials.org\/it\/test-kpss-in-r\/#breadcrumb"},"inLanguage":"it-IT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/it\/test-kpss-in-r\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/it\/test-kpss-in-r\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Casa","item":"https:\/\/statorials.org\/it\/"},{"@type":"ListItem","position":2,"name":"Come eseguire un test kpss in r (incluso un esempio)"}]},{"@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\/2660"}],"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=2660"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts\/2660\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/media?parent=2660"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/categories?post=2660"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/tags?post=2660"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}