I am usually working in Python, but wanted to perform a Chow Test on time series data, which seems to work much better with R's 'strucchange' library.
The Chow Test works, but when plotting it with 'ggplot2' I get the following error for my code:
"Error in new_data_frame(list(xintercept = xintercept)) : object 'dd' not found"
chows<-plyr::dlply(dat1,~variable,function(dd){
point=((1:nrow(dd))[dd$PricingDate==as.POSIXct("2021-05-05 15:00:00 UTC")])
chowtest<-strucchange::sctest(data=dd,value~1,type="Chow",point=point)
fs<-strucchange::Fstats(data=dd,formula=value~1)
breaks<-strucchange::breakpoints(value~1,data=dd)$breakpoints
list(chowtest=chowtest,fs=fs,breaks=breaks)})
breaks<-plyr::ddply(dat1,~variable,function(dd){data.frame(breaks=dd$PricingDate[strucchange::breakpoints(value~1,data=dd)$breakpoints])})
graph<-ggplot(data=dat1,aes(x=PricingDate,y=value))+
geom_line()+
geom_vline(xintercept=dd$PricingDate[point],color="red",alpha=.5,size=3)+
geom_vline(data=breaks,aes(xintercept=breaks))+
facet_wrap(~variable,scales="free")
It might be an easy fix, but I don't quite understand why it can't fetch dd from above or how I can fix it so that it gives me the red bar I want.
Any help highly appreciated, thanks!