Praveen Kumar
Praveen Kumar

Reputation: 11

Is there a way to make an R function return its internal variable?

I am new to R. I am currently trying to implement a regression based on instrumental variable from the sysid R-package. I chose this package since it can predict my instrument.

I found a suitable method ("iv" is the function here) to solve my problem. But the R function is not returning the "Predicted Instrument" as one of its return argument. I am very much interested in that predicted variable. Is there any way to get this variable as an argument?

I already tried to create a clone of this function but it has many dependent function from sysid package so it failed. I also tried to use the "source" command to link this modified function in my R code but rest of the libraries are delinked from my current script. Please provide me any solution to get the predicted instrument. The source code is available below: https://rdrr.io/cran/sysid/src/R/iv.R.

iv4 <- function(z,order=c(0,1,0)){
na <- order[1]; nb <- order[2]
# Steps 1-2
mod_iv <- iv(z,order)

# Step 3
w <- resid(mod_iv)
mod_ar <- ar(w,aic = F,order.max =na+nb)
Lhat <- signal::Arma(b=c(1,-mod_ar$ar),a=1)

# Step 4
x2 <- matrix(sim(mod_iv$sys,inputData(z)))
ivcompute(z,x2,order,Lhat)
}

I want predicted instrument- Lhat to be returned. I also welcome suggestion for using any other package or regression method which can do the same(predict instrument).

Upvotes: 1

Views: 111

Answers (0)

Related Questions