trend_analysis: Categorize trends in a GCAM variable

Description Usage Arguments Input Output Methods Examples

View source: R/trend-analysis.R


This function analyzes trends in an input table of GCAM data values over time. The time series are categorized into a user-defined number of trend types, and these are returned, along with a table identifying each time series with its trend type.


trend_analysis(d, n = 4, valuecol = "value", yearcol = "year")



The data to analyze. See details for a description of the input data format.


Number of categories to produce. For 32-region data, setting n > 8 is not recommended.


Name of the column with the data values in it. The output trends will prepend 'normalized.' to this name for the name of their value column.


Name of the column with the year values in it. The output trends will always call their year column "year".


Input data should be a data frame in long format, with year and value columns and at least one ID column. For example, you might have a table of region, year, and population. The output would then categorize regional population trends. It is also permissible to have more than one ID column; for example, region, sector, year, and output. In this case, each combination of region and sector would be a separate data point for categorization purposes.


The return value is a list containing two elements. The trends element contains a table with columns trend.category, year, and value. It represents a prototype time series for each trend category. The prototype time series is in normalized units, with the largest value in the time series defined to be 1.

The categories element contains all of the columns from the input data set, along with a trend.category column. The original value column will be normalized to the maximum value in each time series, just as the prototype trend time series are. The trend category column indicates which category that time series belonged to.

For example, if the input were a table of region, year, and population, then the trends output will be a table of trend category, year, and population. If four categories were requested, then the prototype time series might correspond to population time series that are (for example) stable, rising then stable, rising continuously, and rising then declining. The categories aren't labled in any way; an analyst would arrive at these labels by looking at the prototype time series returned.

The categories element would contain a table of region and trend category, with each category being a number from 1-4, corresponding to one of the trend categories returned. This table tells you which regions have population trends like those in each of the trend categories.


The structure returned by the trend analysis has a summary method that prints a table of which data ponts were assigned to which categories, along with a count of how many data points were assigned to each category. There is also a plot method that will plot a visualization of the trend categories and their members.


poptrends <- trend_analysis(population, n=4, valuecol='population')
## Not run: 

## End(Not run)

JGCRI/GCAManalysis documentation built on May 15, 2018, 9:25 p.m.