Skip to content

embed?

4 messages · rkevinburton at charter.net, Gabor Grothendieck, Ravi Varadhan +1 more

#
I have a question on the function 'embed'. I ran the example

x <- 1:10
embed(x, dimension=3)

This gives the output:

     [,1] [,2] [,3]
[1,]    3    2    1
[2,]    4    3    2
[3,]    5    4    3
[4,]    6    5    4
[5,]    7    6    5
[6,]    8    7    6
[7,]    9    8    7
[8,]   10    9    8

I don't quite understand the output and why it is useful. First, there are only 8 rows down from 10 and the first element starts with 3. Of course I can think of explanations as to what is occuring but I cannot see how this is useful. I am sure it has application as i see this command used in much of the source but I just cannot see it now.

The documentation states:

Each row of the resulting matrix consists of sequences x[t], x[t-1], ..., x[t-dimension+1], where t is the original index of x. If x is a matrix, i.e., x contains more than one variable, then x[t] consists of the tth observation on each variable. 

This explanation doesn't seem to account for the dimension argument.

Thank you for your comments.

Kevin
#
Its lets you perform rolling summaries using apply:
[1] 2 3 4 5 6 7 8 9

Note that 2 is the mean of 1:3, 3 is the mean of 2:4, ...,
9 is the mean of 8:10.
On Fri, Apr 3, 2009 at 11:04 AM, <rkevinburton at charter.net> wrote:
#
Kevin,

The documentation is quite clear.

What "embedding" does is that it takes a scalar time series, x[t], and
"embeds" it in a higher-dimensional space of dimension, "dimension".  The
entries in the matrix you see are the indices of the time-series.  

So, for example, if dimension = 2, you embed your time-series on a 2-Dim
space: (x, y), where the points are:  (x[2], x[1]), (x[3], x[2]), ...,
(x[N], x[N-1]).
[,1] [,2]
 [1,]    2    1
 [2,]    3    2
 [3,]    4    3
 [4,]    5    4
 [5,]    6    5
 [6,]    7    6
 [7,]    8    7
 [8,]    9    8
 [9,]   10    9
This is allso known as Ruelle-Takens embedding in non-linear dynamical
systems, where this device is helpful in detecting the existence of a
low-dimensional attractor of the time-series.
 
Ravi.

----------------------------------------------------------------------------
-------

Ravi Varadhan, Ph.D.

Assistant Professor, The Center on Aging and Health

Division of Geriatric Medicine and Gerontology 

Johns Hopkins University

Ph: (410) 502-2619

Fax: (410) 614-9625

Email: rvaradhan at jhmi.edu

Webpage:  http://www.jhsph.edu/agingandhealth/People/Faculty/Varadhan.html

 

----------------------------------------------------------------------------
--------


-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
Behalf Of rkevinburton at charter.net
Sent: Friday, April 03, 2009 11:05 AM
To: r-help at r-project.org
Subject: [R] embed?

I have a question on the function 'embed'. I ran the example

x <- 1:10
embed(x, dimension=3)

This gives the output:

     [,1] [,2] [,3]
[1,]    3    2    1
[2,]    4    3    2
[3,]    5    4    3
[4,]    6    5    4
[5,]    7    6    5
[6,]    8    7    6
[7,]    9    8    7
[8,]   10    9    8

I don't quite understand the output and why it is useful. First, there are
only 8 rows down from 10 and the first element starts with 3. Of course I
can think of explanations as to what is occuring but I cannot see how this
is useful. I am sure it has application as i see this command used in much
of the source but I just cannot see it now.

The documentation states:

Each row of the resulting matrix consists of sequences x[t], x[t-1], ...,
x[t-dimension+1], where t is the original index of x. If x is a matrix,
i.e., x contains more than one variable, then x[t] consists of the tth
observation on each variable. 

This explanation doesn't seem to account for the dimension argument.

Thank you for your comments.

Kevin

______________________________________________
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.
#
rkevinburton at charter.net wrote:
following this 'explanation', the first row consists of values x[t],
x[t-1], ... x[t-3+1], that is, x[t], x[t-1], x[t-2].  how does t, the
original index of x, relate to positions in the matrix?  does it
correspond to the row number, or the column number?  it can't be the
former, because then the first row would include x[1], x[0], x[-1] --
nonsense.  it can't be the latter, because the first row would include
x[1], x[1], x[1] (nonsense), and so all other rows (nonsense).

for a vector, say x, the output, say matrix, contains values calculated
as follows:

    m[i,j] = x[i + dimension - j], with i = 1, ...,
length(x)-dimension+1 and j = 1, ..., dimension

so that you have a rolling window over the vector, with row indices
corresponding to the start of the window, and column indices
corresponding to the position within the window.

arguably, the authors could have done their homework better.

vQ