Re: Construcing correlation matrix from time-ordered list
- To: mathgroup at smc.vnet.net
- Subject: [mg54730] Re: Construcing correlation matrix from time-ordered list
- From: Curt Fischer <tentrillion at gmail.NOSPAM.com>
- Date: Mon, 28 Feb 2005 03:27:21 -0500 (EST)
- References: <cvrptk$p0t$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Adam Getchell wrote: > Hello all, > > I have time series data (a lot of it) in a format like: > > {{{1897,1,4},40.37`},{{1897,1,5},40.87`},{{1897,1,6},40.95`},{{1897,1,7}, > 40.87`},{{1897,1,8},40.97`},{{1897,1,11},40.75`},{{1897,1,12}, > 41.4`},{{1897,1,13},41.45`},{{1897,1,14},41.79`},{{1897,1,15}, > 42.27`},{{1897,1,18},42.76`},{{1897,1,19},43.25`},{{1897,1,20}, > 42.78`},{{1897,1,21},42.52`},{{1897,1,22},42.42`}} > > ie the year, then the value, for 100+ years. > > I'd like to construct a correlation matrix so that year values become > columns, e.g. > > 1897 1898 > ========== > Value1 Value 1 > Value 2 Value 2 > ... > > From my long list of {{{date1},value1},{{date2},value2}} > > But I'm not yet sure how to proceed. I'm looking at Cases or Select to > apply a function for each year range that will pick out that column. > > Any pointers appreciated. If your data for each year are all on the same dates (i.e. everything is equally spaced), then it is probably easier to use Partition[]. If not, then this approach below might work. I'm not sure how well it would scale to very long lists. (Note that I added one data point from the year 1898 to your data to see if my method was working.) In[1]:= data = {{{1897, 1, 4}, 40.37}, {{1897, 1, 5}, 40.87}, {{1897, 1, 6}, 40.95}, {{1897, 1, 7}, 40.87}, {{1897, 1, 8}, 40.97}, {{1897, 1, 11}, 40.75}, {{1897, 1, 12}, 41.4}, {{1897, 1, 13}, 41.45}, {{1897, 1, 14}, 41.79}, {{1897, 1, 15}, 42.27}, {{1897, 1, 18}, 42.76}, {{1897, 1, 19}, 43.25}, {{1897, 1, 20}, 42.78}, {{1897, 1, 21}, 42.52}, {{1897, 1, 22}, 42.42}, {{1898, 1, 1}, 40}}; In[2]:= yrlist = Union[data /. {{yr_Integer, mo_Integer, da_Integer}, (val_)?NumericQ} -> yr] Out[2]= {1897, 1898} In[3]:= newData = data /. {{yr_Integer, mo_Integer, da_Integer}, (val_)?NumericQ} -> {yr, val}; In[4]:= (Cases[newData, {#1, (val_)?NumericQ} -> val] & ) /@ yrlist Out[4]= {{40.37, 40.87, 40.95, 40.87, 40.97, 40.75, 41.4, 41.45, 41.79, 42.27, 42.76, 43.25, 42.78, 42.52, 42.42}, {40}} -- Curt Fischer