View source: R/deseasonalized_trend.R
| deseasonalized_trend | R Documentation | 
A convenience function to analyze a timeseries and return an estimate (via gam, using day of week factors and smoothed timestamp) of whether, after accounting for day-of-week, there is a significant time-based influence and what that influence is.
deseasonalized_trend(df, w=NULL)
df | 
 a data frame containing timestamp and value entries  | 
w | 
 number of attempts (n for binomial data)  | 
a list with the following items:
pval | 
 pval given by anova on gam, to indicate whether s(timestamp) is significant  | 
smoothed_prediction | 
 a smoothed prediction over time (on Wednesdays), to give a human-understandable idea of what the change over time has been  | 
Thomas Lotze <thomaslotze@thomaslotze.com>
timestamps = as.numeric(as.POSIXct(seq(as.Date("2012-01-01"),as.Date("2012-05-03"),by=1)))
df=data.frame(timestamp = timestamps, value = rnorm(length(timestamps)))
dt = deseasonalized_trend(df)
if (dt$pval < 0.01) {
  print("Significant time-based factor")
  plot(df$timestamp, dt$smoothed_prediction)
} else {
  print("No significant time-based factor")
}
df=data.frame(timestamp = timestamps,
              value = sapply(timestamps, function(t) {rpois(1, lambda=t-min(timestamps))}))
dt = deseasonalized_trend(df)
if (dt$pval < 0.01) {
  print("Significant time-based factor")
  plot(df$timestamp, dt$smoothed_prediction)
} else {
  print("No significant time-based factor")
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.