Home > Net >  ggplot problem with autocorrelation, one line/variable doesnt scale to 1 at lag 0. But the data show
ggplot problem with autocorrelation, one line/variable doesnt scale to 1 at lag 0. But the data show

Time:05-25

My ggplot of autocorrelation

My correlation values, the red line is defined as Kryds_BNP_BNP

The code im using:

p11 <- ggplot(Autokor) 
  geom_line(aes(x=Lag, y=0)) 
  stat_smooth(aes(y=Kryds_HP_HP, x=Lag, color = "HUSPRIS"), formula = y ~ s(x, k = 11), method = "gam", se = FALSE)  
  stat_smooth(aes(y=Kryds_RENTE_RENTE, x=Lag, color = "RENTE"), formula = y ~ s(x, k = 11), method = "gam", se = FALSE)     
  stat_smooth(aes(y=Kryds_BNP_BNP, x=Lag, color = "BNP"), formula = y ~ s(x, k = 11), method = "gam", se = FALSE)  
  stat_smooth(aes(y=Kryds_KREDIT_KREDIT, x=Lag, color = "KREDIT"), formula = y ~ s(x, k = 11), method = "gam", se = FALSE)  
  scale_y_continuous(labels = function(x) format(x, big.mark = ".", decimal.mark = ",") ,limits = c(-1, 1), breaks=round(seq(min(-1), max(1), by = 0.5),1))  
  scale_x_continuous(labels = function(x) format(x, big.mark = ".", decimal.mark = ",") ,limits = c(-6, 6), breaks=round(seq(min(-6), max(6), by = 1),1))  
  labs(title = "Autokorrelationer", x="Lag", y="Korrelation", caption = "", color=NULL)  theme(legend.position="bottom")   theme(panel.grid.minor.x = element_blank())   th

My problem is that the values shows that the red line (BNP) should have a top at correlation value 1, at lag 0, but in the ggplot BNP top is close to 0.4

CodePudding user response:

The new autocorrelation plot

p11 <- ggplot(Autokor)  geom_line(aes(x=Lag, y=0))  geom_line(aes(y=Kryds_HP_HP, x=Lag, color = "HUSPRIS"), formula = y ~ s(x, k = 11), method = "gam", se = FALSE)   geom_line(aes(y=Kryds_RENTE_RENTE, x=Lag, color = "RENTE"), formula = y ~ s(x, k = 11), method = "gam", se = FALSE)   geom_line(aes(y=Kryds_BNP_BNP, x=Lag, color = "BNP"), formula = y ~ s(x, k = 11), method = "gam", se = FALSE)   geom_line(aes(y=Kryds_KREDIT_KREDIT, x=Lag, color = "KREDIT"), formula = y ~ s(x, k = 11), method = "gam", se = FALSE)   scale_y_continuous(labels = function(x) format(x, big.mark = ".", decimal.mark = ",") ,limits = c(-1, 1), breaks=round(seq(min(-1), max(1), by = 0.5),1))   scale_x_continuous(labels = function(x) format(x, big.mark = ".", decimal.mark = ",") ,limits = c(-6, 6), breaks=round(seq(min(-6), max(6), by = 1),1))   labs(title = "Autokorrelationer", x="Lag", y="Korrelation", caption = "", color=NULL)   theme(legend.position="bottom")   theme(panel.grid.minor.x = element_blank())   th

The problem was that stat_smooth() was to aggressive to approach 1 at lag 0. It therefore solved the problem by replacing stat_smooth(), with geom_line().

  • Related