My R plot of a time series is contradictory with the same plot on a larger time span, why is that?

huangapple go评论56阅读模式
英文:

My R plot of a time series is contradictory with the same plot on a larger time span, why is that?

问题

I am currently working on a univariate time series on R. When I plot the time series over the whole time span, that is, from 1981 to 2022, I get that there is a decreasing trend in the second sub-period (2000 - 2022), whereas when I restrict to this sub period and plot it, it seems constant and even increasing. Why is that? Where is my mistake?

production_2 <-serie_elec$Production brute d&#39;&#233;lectricit&#233; nucl&#233;aire (en GWh)
prod_2 <- ts(serie_elec, frequency=12)
prod_2 <- ts(production_2, start=c(1981,1) , end=c(2022,11), frequency=12)
summary(prod_2)
plot.ts(prod_2)

Here is the first plot My R plot of a time series is contradictory with the same plot on a larger time span, why is that?, that of the whole time series.

production_periode_2 <-serie_elec$Production brute d&#39;&#233;lectricit&#233; nucl&#233;aire (en GWh)
prod_periode_2 <- ts(serie_elec, frequency=12)
prod_periode_2 <- ts(production_periode_2, start=c(2000,1) , end=c(2022,11),
frequency=12)
summary(prod_periode_2)
plot.ts(prod_periode_2)

Here is the second plot My R plot of a time series is contradictory with the same plot on a larger time span, why is that?, that of the time series on the 2nd sub period, from 2000 to 2022.

Here is the structure of both datasets for reproducibility:

> dput(head(prod_2))
structure(c(22951.429, 21465.026, 19334.531, 19319.365, 19923.664,
21275.248), tsp = c(1981, 1981.41666666667, 12), class = "ts")
> dput(head(prod_periode_2))
structure(c(22951.429, 21465.026, 19334.531, 19319.365, 19923.664,
21275.248), tsp = c(2000, 2000.41666666667, 12), class = "ts")

Thanks in advance for your help!

英文:

I am currently working on a univariate time series on R. When I plot the time series over the whole time span, that is, from 1981 to 2022, I get that there is a decreasing trend in the second sub-period (2000 - 2022), whereas when I restrict to this sub period and plot it, it seems constant and even increasing. Why is that ? Where is my mistake ?

  production_2 &lt;-serie_elec$`Production brute d&#39;&#233;lectricit&#233; nucl&#233;aire (en GWh)`
  prod_2 &lt;- ts(serie_elec, frequency=12)
  prod_2 &lt;- ts(production_2, start=c(1981,1) , end=c(2022,11), frequency=12)
  summary(prod_2)
  plot.ts(prod_2)

Here is the first plot My R plot of a time series is contradictory with the same plot on a larger time span, why is that?, that of the whole time series.

 production_periode_2 &lt;-serie_elec$`Production brute d&#39;&#233;lectricit&#233; nucl&#233;aire (en GWh)`
 prod_periode_2 &lt;- ts(serie_elec, frequency=12)
 prod_periode_2 &lt;- ts(production_periode_2, start=c(2000,1) , end=c(2022,11), 
 frequency=12)
 summary(prod_periode_2)
 plot.ts(prod_periode_2)

Here is the second plot My R plot of a time series is contradictory with the same plot on a larger time span, why is that?, that of the time series on the 2nd sub period, from 2000 to 2022.

Here is the structure of both datasets for reproducibility :

  &gt; dput(head(prod_2))
  structure(c(22951.429, 21465.026, 19334.531, 19319.365, 19923.664, 
   21275.248), tsp = c(1981, 1981.41666666667, 12), class = &quot;ts&quot;)
  &gt; dput(head(prod_periode_2))
  structure(c(22951.429, 21465.026, 19334.531, 19319.365, 19923.664, 
  21275.248), tsp = c(2000, 2000.41666666667, 12), class = &quot;ts&quot;)

Thanks in advance for your help !

答案1

得分: 2

You should use a subset of that data in your second call to ts().

Another comment, when you assign to the same variable on two consecutive lines, like this:

prod_periode_2 <- ts(serie_elec, frequency=12)
prod_periode_2 <- ts(production_periode_2, start=c(2000,1), end=c(2022,11), frequency=12)

The first assignment is just overwritten.

英文:

You are giving ts() the same data both times:

serie_elec$`Production brute d&#39;&#233;lectricit&#233; nucl&#233;aire (en GWh)`

The first time you are saying that that data starts in 1981. The second time you are NOT selecting a subperiod. Instead, you are giving it the exact same data, but this time saying that data starts in 2000.

You should use a subset of that data in your second call to ts().

Another comment, when you assign to the same variable on two consecutive lines, like this:

prod_periode_2 &lt;- ts(serie_elec, frequency=12)
prod_periode_2 &lt;- ts(production_periode_2, start=c(2000,1) , end=c(2022,11), frequency=12)

The first assignment is just overwritten.

huangapple
  • 本文由 发表于 2023年5月13日 20:01:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/76242622.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定