Garchfit in R called from Julia: Multivariate data inputs require lhs for the formula

139 views Asked by At

I'm trying to call the R function garchFit from Julia using Rcall. When I do things directly in R, all is well: the following works

    library("fGarch")
    library("rugarch")
    spxData <- read.csv(file = 'SPXlogreturns.csv')
    y = spxData$y
    fit.arch <- garchFit(~garch(1,0),data=y,trace=F,include.mean=FALSE)

But when I have the same vector of log returns in Julia and try to do the same thing using RCall:

    using RCall
    @rput y
    R"""
    library("fGarch")
    library("rugarch")
    fit.arch <- garchFit(~garch(1,0),data=y,trace=F,include.mean=FALSE)
    """

I get the error Multivariate data inputs require lhs for the formula. Yet when I @rget y back from R, it's a vector, so I don't understand what garchFit wants. Any help much appreciated.

1

There are 1 answers

0
David Murphy On

In case anyone googles it and has a similar problem, the answer is that you need to unlist. For no (at least to me) readily obvious reason, @rput creates a list in R, not a vector. So the answer is using RCall @rput y R""" library("fGarch") library("rugarch") yy <- unlist(y) fit.arch <- garchFit(~garch(1,0),data=yy,trace=F,include.mean=FALSE) """