[R] assign estimated values
Rui Barradas
ruipbarradas at sapo.pt
Mon Feb 11 11:41:14 CET 2013
Hello,
Em 11-02-2013 01:26, Pete Brecknock escreveu:
> malaka wrote
>> Hi,
>> I want to assign the ar1 , ma 1 and the intercept estimated by the
>> following code to three variables a, b and c respectively.
>>
>> Can anyone help me with this please?
>>
>> code:
>>
>> a0 = 0.05; a1 = 0.1; b1 = 0.85
>> nu = rnorm(2500)
>> epsi = rep(0, 2500)
>> h = rep(0, 2500)
>> for (i in 2: 2500) { h[i] = a0 + a1 * epsi[i-1]^2 + b1 * h[i-1] ; epsi[i]
>> = nu[i] * sqrt(h[i])}
>> epsi = epsi[1501:2500]
>> epsi=epsi*epsi
>> arma(epsi,order=c(1,1))
>
> You haven't specified a library for the arma function. Your code doesn't
> work for me in the form you posted it.
If it's function arma(9 in package tseries, then your solution below
also works. tseries::arma returns an object of class "arma",
mod <- arma(epsi, order=c(1,1))
str(mod)
List of 12
$ coef : Named num [1:3] 0.971 -0.9214 0.0325
..- attr(*, "names")= chr [1:3] "ar1" "ma1" "intercept"
$ css : num 2416
$ n.used : int 1000
$ residuals : num [1:1000] NA 0.105 0.1747 0.0144 0.0435 ...
$ fitted.values : Time-Series [1:1000] from 1 to 1000: NA 0.175
0.208 0.243 0.269 ...
$ series : chr "epsi"
$ frequency : num 1
$ call : language arma(x = epsi, order = c(1, 1))
$ vcov : num [1:3, 1:3] 0.000203 -0.00028 -0.000224
-0.00028 0.00053 ...
..- attr(*, "dimnames")=List of 2
.. ..$ : chr [1:3] "ar1" "ma1" "intercept"
.. ..$ : chr [1:3] "ar1" "ma1" "intercept"
$ lag :List of 2
..$ ar: int 1
..$ ma: int 1
$ convergence : int 0
$ include.intercept: logi TRUE
- attr(*, "class")= chr "arma"
mod$coef is a named vector, with names "ar1", "ma1" and "intercept".
Hope this helps,
Rui Barradas
>
> However, changing ...
>
> arma(epsi, order=c(1,1)) to
>
> mod = arima(epsi, order=c(1,0,1))
>
> You can extract the parameters of interest using
>
> a= mod$coef["ar1"]
> b= mod$coef["ma1"]
> c= mod$coef["intercept"]
>
> HTH
>
> Pete
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/assign-estimated-values-tp4658139p4658141.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
More information about the R-help
mailing list