Как реализовать скрипт r в приложении Ruby on Rails - PullRequest
0 голосов
/ 03 октября 2018

Мне нужно запустить скрипт R для группы данных в приложении RoR.Я пытался использовать yth_filter ( см. Здесь ), но время отклика составляло 15+ секунд.Кто-нибудь знает о преобразовании сортов или лучший способ реализовать этот сценарий R?


## Filter macro series
# Filtering parameters

#   A user will need to enter these  
#   values into interactive fields
#   to adjust the trend line.
#   h = number of periods forecasted
#       into the future.
#   p = number of previous values
#       selected as independent
#       variables.

    rm(list=ls())

    # Get the file   
    y <- read.csv('D:/Papers/cato/cmfa_filtering/NGDP.csv', header=TRUE, row.names=1)
    y <- xts(y, order.by = as.Date(rownames(y), format="%m/%d/%Y"))

    # Parameters
    h <- 8
    p <- 4

    # Initialize
    lag <- h

    # Generate the lags
    for (i in 1:p) {    
      # Create the lagged variable
      assign(paste0('y', i), lag.xts(y, k=lag))    
      # Tick ahead
      lag <- lag+1
    }    
    # Do OLS
    ols <- lm(y~y1+y2+y3+y4)

    # Get the trend and cycle components
    out.trend <- fitted(ols)
    out.cycle <- resid(ols)

    # Compare to yth_filter
    out.pack <- yth_filter(y, h=h, p=p, output=c("x", "trend"), family = gaussian)
    compare <- cbind.xts(out.pack,out.trend)
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...