search()
require(gmm)
search()
rm(list=ls())
search()
?detach
dplyr::select()
search()
a <- 1
gmm
gmm::gmm
?hac
library(sandwich)
?hac
vcov
?vcov
install.packages("gmm")
library(PointFore)
PointFore::estimate.functional
# load data
library(PointFore)
library(ggplot2)
load("./data-raw/precipitation data.RData")
prec <- prec_London
Temp <- temp_London
N <- dim(prec)[1]
cur.forecast <- 'HRES'
interval.time <- (dim(prec)[1]-N):dim(prec)[1]
Y <- prec[interval.time,"24h", c('Y')]
X <- prec[interval.time,"24h", c(paste0('X_',cur.forecast))]
Temp <- Temp[interval.time, "24h", c(paste0('Z_',cur.forecast))]
precipitation <- data.frame(Y=Y,X=X)
instruments <- c("lag(lag(Y))","X")
instrumentsA <- c("X","X^2","lag(lag(Y))")
instruments2 <- c("lag(Y)","X","X^2","X^3","lag(Y-X)^2")
##### Constant expectile
res <- estimate.functional(iden.fct = expectiles, model = constant,
instruments = instruments,
Y = Y, X=X)
summary(res)
plot(res,hline = TRUE)
inv.logit(0.174)
# Expectile
res <- estimate.functional(iden.fct = expectiles,
model = probit_linear,
instruments = instruments,
state = X,
Y = Y, X = X)
summary(res$gmm)
logistic0 <- function(stateVariable,theta) logistic_linear(stateVariable, theta)*(stateVariable>0)
# Expectile alternative model with 0
res <- estimate.functional(iden.fct =   expectiles ,model = logistic0,
theta0 = c(0,0),
instruments = instruments,
state = X,
Y = Y, X=X)
summary(res)
probit0 <- function(stateVariable,theta) probit_linear(stateVariable, theta)*(stateVariable>0)
res <- estimate.functional(iden.fct =   expectiles ,
model = probit0,
theta0 = c(0,0),
instruments = instruments,
state = X,
Y = Y, X=X)
summary(res)
#0.73
plot(res)
threshold <- 0
mean(X<=threshold)
plot(res,limits = c(0.001,15),hline = TRUE#,conf.levels = c(0.9,0.99)
)+
geom_point(data=data.frame(x=c(0,0),y=c(0,.395),shape=c(1,2)),
aes(x=x,y=y,shape=as.factor(shape)),
,size=3,show.legend = FALSE)+
scale_shape_manual(values=c(16,1))+
scale_y_continuous("expectile level")+
xlab("predicted precipitation")+theme_classic(20)
summary(res)
res <- estimate.functional(iden.fct =   expectiles ,
model = probit0,
theta0 = c(0,0),
instruments = instruments,
state = X,
centeredVcov=FALSE,
Y = Y, X=X)
summary(res)
res <- estimate.functional(iden.fct =   expectiles ,
model = probit0,
theta0 = c(0,0),
instruments = instruments,
state = X,
#centeredVcov=FALSE,
Y = Y, X=X)
summary(res)
res <- estimate.functional(iden.fct =   expectiles ,
model = probit0,
theta0 = c(0,0),
instruments = instruments,
state = X,
centeredVcov=FALSE,
Y = Y, X=X)
summary(res)
plot(res,limits = c(0.001,15),hline = TRUE#,conf.levels = c(0.9,0.99)
)+
geom_point(data=data.frame(x=c(0,0),y=c(0,.395),shape=c(1,2)),
aes(x=x,y=y,shape=as.factor(shape)),
,size=3,show.legend = FALSE)+
scale_shape_manual(values=c(16,1))+
scale_y_continuous("expectile level")+
xlab("predicted precipitation")+theme_classic(20)
ggsave('./data-raw/prec.pdf', height = 5, width=8)
# other information set X_t Y_t-2
res <- estimate.functional(iden.fct =   expectiles ,
model = probit0,
theta0 = c(0,0),
instruments = c("X","lag(lag(Y))"),
state = X,
Y = Y, X=X)
summary(res)
instruments
#### state as lag Y
res <- estimate.functional(iden.fct =   expectiles ,model = probit0,
theta0 = c(0,0),
instruments = instruments,
state = lag(Y),
Y = Y, X=X)
summary(res)
library(lubridate)
library(PointFore)
library(xlsx)
# load observations
#Y<- read.csv("./data-raw/observations.csv", sep=";", dec=",", header=TRUE)
Y <- read.xlsx2("./data-raw/routput_first_second_third_all.xlsx",
sheetIndex = 2,startRow = 5)
library(PointFore)
GDPanalyse <- function(model, instruments, forecast, iden.fct=quantiles,...)
{
estimate.functional(iden.fct = iden.fct,
model = model,
instruments = instruments,
Y = GDP$observation,X = forecast,
stateVariable = forecast,...)
}
test <- function(string,res)
{
return(car::linearHypothesis(res$gmm,string))
}
conf <- function(res,name,level=0.90)
{
confint(res$gmm,parm=name,level=level)
}
early <- c("X","lag(Y)")
standard <- c("X","lag(lag(Y))")
simulation <- c("lag(Y)","X","X^2","X^3","lag(Y-X)","lag(Y-X)^2")
summary(GDPanalyse(constant,standard,GDP$forecast))
#0.05
test("Theta[1]=.5",GDPanalyse(constant,standard,GDP$forecast))
summary(GDPanalyse(constant,c("X","lag(lag(Y))"),GDP$forecast, expectiles))
#0.02
test("Theta[1]=.5",GDPanalyse(constant,standard,GDP$forecast))
summary(GDPanalyse(constant,standard,GDP$forecast_late))
#0.25
test("Theta[1]=.5",GDPanalyse(constant,standard,GDP$forecast_late))
#0.03
conf(GDPanalyse(constant,standard,GDP$forecast_late), "Theta[1]")
res <- GDPanalyse(constant,standard,GDP$forecast_late)
conf(res,"Theta[1]")
res <- GDPanalyse(constant,standard,GDP$forecast_late)
summary(res)$Jtest
conf(res,"Theta[1]")
conf(res,"Theta[1]",level = 0.6)
test("Theta[1]=.5",res)
res <- GDPanalyse(constant,standard,GDP$forecast_late,expectiles)
summary(res)$coefficients
summary(res)$Jtest
conf(res,"Theta[1]")
conf(res,"Theta[1]",level = 0.6)
test("Theta[1]=.5",res)
res <- GDPanalyse(constant,standard,GDP$forecast)
summary(res)$Jtest
conf(res,"Theta[1]")
test("Theta[1]=.5",res)
res <- GDPanalyse(constant,simulation,GDP$forecast)
summary(res)$Jtest
conf(res,"Theta[1]")
test("Theta[1]=.5",res)
res <- GDPanalyse(constant,standard,GDP$forecast,expectiles)
summary(res)$Jtest
test("Theta[1]=.5",res)
res <- GDPanalyse(constant,simulation,GDP$forecast,expectiles)
summary(res)$Jtest
test("Theta[1]=.5",res)
res <- GDPanalyse(constant,early,GDP$forecast,expectiles)
summary(res)$Jtest
test("Theta[1]=.5",res)
# Analyse - linear probit -------------------------------------------------
library(ggplot2)
res <- GDPanalyse(probit_linear,standard,GDP$forecast)
summary(res)
res$gmm$vcov
plot(res,limits=c(-5,10),hline=TRUE)+  xlab("predicted growth rate")+
theme_classic(20)+
scale_y_continuous("quantile level", limits=c(0,1))
res <- GDPanalyse(probit_linear,standard,GDP$forecast_late)
summary(res)
res <- GDPanalyse(probit_linear,standard,GDP$forecast_late)
summary(res)
plot(res,hline = TRUE)
res <- GDPanalyse(probit_linear,standard,GDP$forecast)
summary(res)
GDPanalyse <- function(model, instruments, forecast, iden.fct=quantiles,...)
{
estimate.functional(iden.fct = iden.fct,
model = model,
centeredVcov=FALSE,
instruments = instruments,
Y = GDP$observation,X = forecast,
stateVariable = forecast,...)
}
test <- function(string,res)
{
return(car::linearHypothesis(res$gmm,string))
}
conf <- function(res,name,level=0.90)
{
confint(res$gmm,parm=name,level=level)
}
early <- c("X","lag(Y)")
standard <- c("X","lag(lag(Y))")
simulation <- c("lag(Y)","X","X^2","X^3","lag(Y-X)","lag(Y-X)^2")
summary(GDPanalyse(constant,standard,GDP$forecast))
#0.05
test("Theta[1]=.5",GDPanalyse(constant,standard,GDP$forecast))
summary(GDPanalyse(constant,c("X","lag(lag(Y))"),GDP$forecast, expectiles))
summary(GDPanalyse(constant,standard,GDP$forecast))
summary(GDPanalyse(constant,standard,GDP$forecast))
#0.05
test("Theta[1]=.5",GDPanalyse(constant,standard,GDP$forecast))
summary(GDPanalyse(constant,c("X","lag(lag(Y))"),GDP$forecast, expectiles))
#0.02
test("Theta[1]=.5",GDPanalyse(constant,standard,GDP$forecast))
summary(GDPanalyse(constant,standard,GDP$forecast_late))
#0.25
test("Theta[1]=.5",GDPanalyse(constant,standard,GDP$forecast_late))
summary(GDPanalyse(constant,standard,GDP$forecast_late))
summary(GDPanalyse(constant,standard,GDP$forecast_late))
res <- GDPanalyse(constant,standard,GDP$forecast_late)
conf(res,"Theta[1]")
res <- GDPanalyse(constant,standard,GDP$forecast_late)
summary(res)$Jtest
conf(res,"Theta[1]")
conf(res,"Theta[1]",level = 0.6)
test("Theta[1]=.5",res)
res <- GDPanalyse(constant,standard,GDP$forecast_late,expectiles)
summary(res)$coefficients
summary(res)$Jtest
conf(res,"Theta[1]")
conf(res,"Theta[1]",level = 0.6)
test("Theta[1]=.5",res)
res <- GDPanalyse(constant,standard,GDP$forecast)
summary(res)$Jtest
conf(res,"Theta[1]")
test("Theta[1]=.5",res)
res <- GDPanalyse(constant,standard,GDP$forecast)
summary(res)$Jtest
conf(res,"Theta[1]")
test("Theta[1]=.5",res)
summary(GDPanalyse(constant,standard,GDP$forecast))
summary(GDPanalyse(constant,standard,GDP$forecast))
#0.05
test("Theta[1]=.5",GDPanalyse(constant,standard,GDP$forecast))
summary(GDPanalyse(constant,standard,GDP$forecast))
#0.05
test("Theta[1]=.5",GDPanalyse(constant,standard,GDP$forecast))
summary(GDPanalyse(constant,standard,GDP$forecast_late))
#0.25
test("Theta[1]=.5",GDPanalyse(constant,standard,GDP$forecast_late))
#0.03
conf(GDPanalyse(constant,standard,GDP$forecast_late), "Theta[1]")
res <- GDPanalyse(constant,standard,GDP$forecast_late)
conf(res,"Theta[1]")
res <- GDPanalyse(constant,standard,GDP$forecast_late)
summary(res)$Jtest
conf(res,"Theta[1]")
conf(res,"Theta[1]",level = 0.6)
test("Theta[1]=.5",res)
res <- GDPanalyse(constant,standard,GDP$forecast)
summary(res)$Jtest
conf(res,"Theta[1]")
test("Theta[1]=.5",res)
res <- GDPanalyse(constant,simulation,GDP$forecast)
summary(res)$Jtest
conf(res,"Theta[1]")
test("Theta[1]=.5",res)
res <- GDPanalyse(constant,standard,GDP$forecast,expectiles)
# Analyse - linear probit -------------------------------------------------
library(ggplot2)
res <- GDPanalyse(probit_linear,standard,GDP$forecast)
summary(res)
res$gmm$vcov
plot(res,limits=c(-5,10),hline=TRUE)+  xlab("predicted growth rate")+
theme_classic(20)+
scale_y_continuous("quantile level", limits=c(0,1))
ggsave('./data-raw/GDP_newInstruments.pdf', height = 5, width=8)
summary(GDPanalyse(constant,standard,GDP$forecast))
#0.05
test("Theta[1]=.5",GDPanalyse(constant,standard,GDP$forecast))
summary(GDPanalyse(constant,standard,GDP$forecast))
# Analyse - linear probit -------------------------------------------------
library(ggplot2)
res <- GDPanalyse(probit_linear,standard,GDP$forecast)
summary(res)
res$gmm$vcov
summary(res)
#0.05
test("Theta[1]=.5",GDPanalyse(constant,standard,GDP$forecast))
summary(GDPanalyse(constant,standard,GDP$forecast_late))
# load data
library(PointFore)
library(ggplot2)
load("./data-raw/precipitation data.RData")
prec <- prec_London
Temp <- temp_London
N <- dim(prec)[1]
cur.forecast <- 'HRES'
interval.time <- (dim(prec)[1]-N):dim(prec)[1]
Y <- prec[interval.time,"24h", c('Y')]
X <- prec[interval.time,"24h", c(paste0('X_',cur.forecast))]
Temp <- Temp[interval.time, "24h", c(paste0('Z_',cur.forecast))]
precipitation <- data.frame(Y=Y,X=X)
instruments <- c("lag(lag(Y))","X")
instrumentsA <- c("X","X^2","lag(lag(Y))")
instruments2 <- c("lag(Y)","X","X^2","X^3","lag(Y-X)^2")
##### Constant expectile
res <- estimate.functional(iden.fct = expectiles, model = constant,
instruments = instruments,
Y = Y, X=X)
summary(res)
plot(res,hline = TRUE)
inv.logit(0.174)
# Expectile
res <- estimate.functional(iden.fct = expectiles,
model = probit_linear,
instruments = instruments,
state = X,
Y = Y, X = X)
summary(res$gmm)
probit0 <- function(stateVariable,theta) probit_linear(stateVariable, theta)*(stateVariable>0)
res <- estimate.functional(iden.fct =   expectiles ,
model = probit0,
theta0 = c(0,0),
instruments = instruments,
state = X,
centeredVcov=FALSE,
Y = Y, X=X)
summary(res)
?gmm
??gmm
library(PointFore)
# late GDP optimal constant quantiles/expectiles --------------------------
res <- estimate.functional(iden.fct = expectiles,
model = constant,
instruments = instruments,
Y = GDP2$observation,X = GDP2$forecast,
stateVariable = GDP2$forecast)
instruments <- c("X","lag(Y,2)")
# late GDP optimal constant quantiles/expectiles --------------------------
res <- estimate.functional(iden.fct = expectiles,
model = constant,
instruments = instruments,
Y = GDP2$observation,X = GDP2$forecast,
stateVariable = GDP2$forecast)
library(PointFore)
GDPanalyse <- function(model, instruments, forecast, iden.fct=quantiles,...)
{
estimate.functional(iden.fct = iden.fct,
model = model,
centeredVcov=FALSE,
instruments = instruments,
Y = GDP$observation,X = forecast,
stateVariable = forecast,...)
}
test <- function(string,res)
{
return(car::linearHypothesis(res$gmm,string))
}
conf <- function(res,name,level=0.90)
{
confint(res$gmm,parm=name,level=level)
}
early <- c("X","lag(Y)")
standard <- c("X","lag(lag(Y))")
simulation <- c("lag(Y)","X","X^2","X^3","lag(Y-X)","lag(Y-X)^2")
summary(GDPanalyse(constant,standard,GDP$forecast))
#0.05
test("Theta[1]=.5",GDPanalyse(constant,standard,GDP$forecast))
summary(GDPanalyse(constant,standard,GDP$forecast_late))
#0.30
test("Theta[1]=.5",GDPanalyse(constant,standard,GDP$forecast_late))
#0.02
conf(GDPanalyse(constant,standard,GDP$forecast_late), "Theta[1]")
res <- GDPanalyse(constant,standard,GDP$forecast_late)
conf(res,"Theta[1]")
res <- GDPanalyse(constant,standard,GDP$forecast_late)
summary(res)$Jtest
conf(res,"Theta[1]")
conf(res,"Theta[1]",level = 0.6)
test("Theta[1]=.5",res)
res <- GDPanalyse(constant,standard,GDP$forecast)
summary(res)$Jtest
conf(res,"Theta[1]")
test("Theta[1]=.5",res)
# Analyse - linear probit -------------------------------------------------
library(ggplot2)
res <- GDPanalyse(probit_linear,standard,GDP$forecast)
summary(res)
res$gmm$vcov
plot(res,limits=c(-5,10),hline=TRUE)+  xlab("predicted growth rate")+
theme_classic(20)+
scale_y_continuous("quantile level", limits=c(0,1))
res <- GDPanalyse(probit_linear,standard,GDP$forecast_late)
summary(res)
res <- GDPanalyse(probit_linear,standard,GDP$forecast)
summary(res)
res <- estimate.functional(Y=GDP$observation,X=GDP$forecast)
summary(res)
?estimate.functional
res <- estimate.functional(Y=GDP$observation,X=GDP$forecast_late)
summary(res)
res <- estimate.functional(Y=GDP$observation,X=GDP$forecast)
summary(res)
res <- estimate.functional(Y=GDP$observation,
X=GDP$forecast,
instruments = c("X","lag(Y,2)"))
summary(res)
plot(res)
res <- estimate.functional(Y=GDP$observation,X=GDP$forecast,
model=probit_linear,
instruments = c("X","lag(Y,2)"),
stateVariable = GDP$forecast)
summary(res)
plot(res)
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
res <- estimate.functional(model = probit_linear,
state = GDP$forecast,
instruments = c("X","lag(Y,2)"),
Y=GDP$observation,
X=GDP$forecast)
summary(res)
plot(res,hline = TRUE)
res <- estimate.functional(model = probit_linear,
instruments = c( "X", "lag(X)"),
state = GDP$forecast, Y=GDP$observation,X=GDP$forecast)
summary(res)
plot(res,hline = TRUE)
devtools::build_vignettes()
library(lubridate)
library(PointFore)
library(openxlsx)
# load observations
Y <- read.xlsx("./data-raw/routput_first_second_third_all.xlsx",
sheet = 2,startRow = 5)
#convert to numeric
Y[,-1] <- t(apply(Y[,-1], 1,function(x) as.numeric(as.character(x))))
# read forecasts
X <- read.xlsx2("./data-raw/GBweb_Row_Format.xls", 2)[,c("DATE","gRGDPF1", "GBdate")]
X$gRGDPF1 <- as.numeric(as.character(X$gRGDPF1))
# format date
X$date <- as.Date(as.character(X$GBdate),"%Y%m%d")
X$date.target <- X$date+days(90)
# read forecasts
X <- read.xlsx2("./data-raw/GBweb_Row_Format.xls", 2)[,c("DATE","gRGDPF1", "GBdate")]
# read forecasts
X <- read.xlsx("./data-raw/GBweb_Row_Format.xls", 2)[,c("DATE","gRGDPF1", "GBdate")]
# read forecasts
X <- read.xls("./data-raw/GBweb_Row_Format.xls", 2)[,c("DATE","gRGDPF1", "GBdate")]
library(Gdat)
library(gdat)
install.packages("gdata")
library(gdata)
# read forecasts
X <- read.xls("./data-raw/GBweb_Row_Format.xls", 2)[,c("DATE","gRGDPF1", "GBdate")]
read.xls("./data-raw/GBweb_Row_Format.xls", 2)
read.xls("./data-raw/GBweb_Row_Format.xls"
)
# read forecasts
X <- read.xls(perl = "./data-raw/GBweb_Row_Format.xls", 2)[,c("DATE","gRGDPF1", "GBdate")]
# read forecasts
X <- read.xls(perl = "./data-raw/GBweb_Row_Format.xls", sheet = 2)[,c("DATE","gRGDPF1", "GBdate")]
install.packages("xlsx")
library(xlsx)
# load observations
Y <- read.xlsx("./data-raw/routput_first_second_third_all.xlsx",
sheet = 2,startRow = 5)
#convert to numeric
Y[,-1] <- t(apply(Y[,-1], 1,function(x) as.numeric(as.character(x))))
# read forecasts
X <- read.xlsx2("./data-raw/GBweb_Row_Format.xls", 2)[,c("DATE","gRGDPF1", "GBdate")]
library(xlsx)
# load observations
Y <- read.xlsx("./data-raw/routput_first_second_third_all.xlsx",
sheet = 2,startRow = 5)
library(lubridate)
library(PointFore)
library(xlsx)
write.csv(PointFore::GDP,"./data-raw/data archiv/gdp_from_package.csv")
write.csv(PointFore::precipitation,"./data-raw/data archiv/precipitation_from_package.csv")
?PointFore::precipitation
?PointFore::GDP
