# [R] indexed expression

Uwe Ligges ligges at statistik.tu-dortmund.de
Sat Dec 27 17:17:43 CET 2008

```
bernardo lagos alvarez wrote:
> Hello expeRts,
>
> I need generate symbolize the autocovariances matrix of a Gaussian
> ARMA(1,1), for derivate it and evaluate.
> I try this codes, but whitout sucess
>
> vacv<-NULL
>  vacv[1]<-expression(1-2*phi*theta-theta^2)
>  vacv[2]<-(1-phi*theta)*(phi-theta)
>  vacv[3:n]<-acv[2]*(phi^(1:(n-2)))
>  facv<-list()
> for(i in 1:2)
> facv[[i]]<-deriv(y~vacv[i],c("phi","theta"),function(phi,theta){})
> Erro en deriv.formula(y ~ vacv[i], c("phi", "theta"), function(phi, theta) { :
>         Función '`[`' no está en la tabla de derivadas

1. Please try to provide English error messages.
2. If you want deriv to work on the expressions for vacv[], then please
do it rather than ttrying to work on already evaluated expressions as
you do.

One exmaple that works would be to say:
vacv <- NULL
vacv[1] <- expression(1-2*phi*theta-theta^2)
...
and later on:
deriv(vacv[i], c("phi", "theta"), function(phi,theta){})

of yourse, you need to evaluate vacv later on if you really want to
calculate the values....

Uwe Ligges

>
> dfg<-for(n in 1:2) as.formula(sprintf("y~(1 - phi * theta) * (phi -
> theta)*phi^ %d",n))
>  dfg
> y ~ (1 - phi * theta) * (phi - theta) * phi^2
> deriv(dfg[[1]],phi)
> Erro en deriv.default(expr, namevec, function.arg, tag, hessian) :
>         nombres de variable inválidos
>
> Give me a help, please.
>
> Bernardo.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help