alphahat_LR_one_Rcpp: Estimates PWD Parameter alpha by Maximum Marginal Predictive...

Description Usage Arguments Value Examples

View source: R/functions-code.R

Description

This is the main function of the package. It takes as inputs the time series data as response, as well as a predictor matrix, excluding the intercept column, and other settings. It returns as outputs a scalar representing the value of alpha which maximizes the marginal predictive likelihood of the data given the grid of alpha values considered.

Usage

1
2
alphahat_LR_one_Rcpp(y, X = FALSE, alpha.grid = seq(0.65, 1, length.out =
  150), init = 2, plotting = TRUE)

Arguments

y

T-length time series vector. y[1] represents the beginning of the time eries.

X

[T x p] dimensional matrix of covariates. This should not include the intercept column. If X is FALSE, intercept model is run.

alpha.grid

Grid of alpha values over which to compute the marginal predictive likelihood.

init

integer representing the time point to begin computing marginal predictive likelihoods.

plotting

If TRUE, plot the marginal predictive distribution of alpha.

Value

Return a scalar value representing the value of alpha which maximizes the marginal predictive likelihood of the data over the grid of alpha values considered.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
set.seed(12)
N=80
err = rnorm(N)
X = 1:N
slopes = c(rep(1.5,40),rep(2,N-40))
y = rep(5,N) + slopes*X + err
init=6                
alpha.grid = seq(.75,1,length.out=40)
alphahat=alphahat_LR_one_Rcpp(y=y,X=X,alpha.grid=alpha.grid,init=init,plotting=TRUE)
alpha1 = 1.0
coeffs1 = bhat.func(y,X,alpha1)
alpha2 = alphahat
coeffs2 = bhat.func(y,X,alpha2)
plot(x=X,y=y)
abline(a=coeffs2[1],b=coeffs2[2],lty=2,col="red")
abline(a=coeffs1[1],b=coeffs1[2],lty=2)
legend("right", legend=c("OLS","PWD"), col=c(1,2), lty=c(2,2), lwd=c(1,1))

PWD documentation built on May 2, 2019, 10:21 a.m.