英文:
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'électricité nuclé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 , that of the whole time series.
production_periode_2 <-serie_elec$Production brute d'électricité nuclé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 , 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 <-serie_elec$`Production brute d'électricité nuclé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 , that of the whole time series.
production_periode_2 <-serie_elec$`Production brute d'électricité nuclé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 , 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 !
答案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'électricité nuclé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 <- 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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论