[R] Extracting results from the VAR output
David Winsemius
dwinsemius at comcast.net
Fri Jul 27 19:02:41 CEST 2012
On Jul 27, 2012, at 4:34 AM, Rui Barradas wrote:
> Hello,
>
> I'm not familiar with package urca but your problem seems to be in
> the access of a list member.
> The operator '$' is an alternative to '[[', and you are right, the
> latter is recommended programmatically.
>
> Try something along the lines of the following.
>
> VARrow[[ "varresult" ]][[ "Liabilities" ]]
That was equivalent to the original code and does not address the
question posed.
>
> And note that you can use numbers instead of the members' names.
> str(VARrow) would give the structure of the variable and the
> appropriate numbers to use (just count).
>
> Hope this helps,
>
> Rui Barradas
>
> Em 27-07-2012 09:57, Rmillan escreveu:
>> Hi everyone,
>>
>> I'm working with the Vector Autoregressive Model (VAR), and it
>> seems like
>> the ur.ca package provides the best
>> function for this purpose.
>> My problem is, that I don't know how to extract a certain value
>> from the
>> output without using the variables names.
>> I was hoping that this could be done by using numerical value, e.g.
>> [1],
>> instead of writing for instance $Liabilities. The reason why I want
>> to do
>> this is, that this would help me to automize the process, since I
>> may not
>> use the variable Liabilities next time.
>>
>> Here is an example when the process works, but I have to do it
>> manually by
>> typing in $Liabilities
>>
>> VARrow<-VAR(data,p=1,type="const")
>> row<-VARrow$varresult$Liabilities$coefficient
>> row[1]
>>
>> Liabilities.l1
>> 0.06898797
>>
>> It would be nice if I could type in e.g. colnames(data)[1] instead of
>> Liabilities (because colnames(data)[1] referes to Liabilites) but
>> this
>> command just says the value is NULL instead 0.06898797....
If colnames(data)[1] typed at the console would return exactly
"Liabilities" then you could have used:
row <- VARrow$varresult[[ colnames(data)[1] ]]$coefficient
The colnames(data)[1] expression will get evaluated and the character
value substituted in the "[[" argument. I worry that may not be the
correct solution because the name of that result is not "Liabilities"
but rather "Liabilities.l1". You really _should_ present a better
problem description, with at the very least the output of str(VARrow)
or .... more preferably the output of dput(head(VARrow)).
--
David Winsemius, MD
Alameda, CA, USA
More information about the R-help
mailing list