I want to use vars::VAR and vars::roots functions in my package's ".R" file (i.e., StabilityPlot.R [Stability of VAR(p) accross p]; the function code is below).
With roxygenization in consideration, how can I perform this?
The followings come into my mind:
#' @importFrom vars VAR roots
or
#' @importFrom vars VAR
#' @importFrom vars roots
or
#' @importFrom(vars, roots, VAR)
Which one should I use? Or all the above wrong? Any clue? Thx.
StabilityPlot <- function(data, p=5, type = c("const","trend","both","none"))
{
out <- list()
data <- as.data.frame(data)
maxmodulusofinverseroots <- matrix(, nrow = p, ncol =1)
#........................................................................
if (type==c("const")) {
maxmodulusofinverseroots[,1] <- matrix(unlist(lapply(as.matrix(1:p),function(x){max(roots(VAR(mydata, p=x, type = "const"), modulus=TRUE))})), ncol=1)
}
if (type==c("trend")) {
maxmodulusofinverseroots[,1] <- matrix(unlist(lapply(as.matrix(1:p),function(x){max(roots(VAR(mydata, p=x, type = "trend"), modulus=TRUE))})), ncol=1)
}
if (type==c("both")) {
maxmodulusofinverseroots[,1] <- matrix(unlist(lapply(as.matrix(1:p),function(x){max(roots(VAR(mydata, p=x, type = "both"), modulus=TRUE))})), ncol=1)
}
if (type==c("none")) {
maxmodulusofinverseroots[,1] <- matrix(unlist(lapply(as.matrix(1:p),function(x){max(roots(VAR(mydata, p=x, type = "both"), modulus=TRUE))})), ncol=1)
}
out$maxmoduluses <- maxmodulusofinverseroots
#........................................................................
if (type==c("const")) {
plot(ts(maxmodulusofinverseroots), plot.type="single", xlab="p (order of VAR)", main="Stability of VAR(p) accross p; det.regr:const", ylab="MaxModOfInvRootsOfARchrPoly", col=c("black"), lty=1:2)
}
if (type==c("trend")) {
plot(ts(maxmodulusofinverseroots), plot.type="single", xlab="p (order of VAR)", main="Stability of VAR(p) accross p; det.regr:trend", ylab="MaxModOfInvRootsOfARchrPoly", col=c("black"), lty=1:2)
}
if (type==c("both")) {
plot(ts(maxmodulusofinverseroots), plot.type="single", xlab="p (order of VAR)", main="Stability of VAR(p) accross p; det.regr:both", ylab="MaxModOfInvRootsOfARchrPoly", col=c("black"), lty=1:2)
}
if (type==c("none")) {
plot(ts(maxmodulusofinverseroots), plot.type="single", xlab="p (order of VAR)", main="Stability of VAR(p) accross p; det.regr:none", ylab="MaxModOfInvRootsOfARchrPoly", col=c("black"), lty=1:2)
}
abline(1,0)
out
}
Both of your first two suggestions should work. You can see a copy of the roxygen2 manual here. Page 3 has the answer to your question.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With