1
$\begingroup$

the question is trivial, but is there any statistical test (can be done in R) to show that the median is changing in a time-series?? For example, if you go to the following link, you would notice that, after the first few samples (6 or 7), the time series takes a sharp rise. I was wondering if there is a formal statistical way of saying it!

https://docs.google.com/file/d/0B6GUNg-8d30vMzB3cUxJM1dBbXc/edit?usp=sharing

$\endgroup$

migrated from stackoverflow.com May 9 '13 at 20:01

This question came from our site for professional and enthusiast programmers.

  • $\begingroup$ Why the median and not the mean? A test for a change in the latter is called the Chow test and I'm sure it's not hard to find. $\endgroup$ – RoyalTS May 9 '13 at 18:26
  • $\begingroup$ Asking about statistical methodologies is Off Topic for StackOverflow. $\endgroup$ – joran May 9 '13 at 18:29
1
$\begingroup$

As Nick has pointed out, you must take into account any auto-correlative structure that exists in the data. You might want to review Automatic detection of level changes in series of prices which discusses testing for level shifts in the mean. Whether you use the mean or the median is irrelevant to that discussion. The only "advantage" of using the median is that pulse and seasonal pulse anomalies are effectively suppressed when using the median while level/step shifts and local time trends are not.

$\endgroup$
0
$\begingroup$

There is a test called Mood's median test for this. However the R version of it is a bit complicated. See the discussion here: https://stat.ethz.ch/pipermail/r-help/2010-April/234387.html

$\endgroup$
  • 1
    $\begingroup$ Standard tests for comparing medians (or means for that matter) are of little use here unless modified to match the dependence structure of time series. $\endgroup$ – Nick Cox Aug 8 '13 at 8:58
0
$\begingroup$

There is a new R package, changepoint.np which detects changes in the empirical distribution function. A minimal working example (demonstrated using a Normal distribution but it is a nonparametric test) is:

set.seed(1)
x=c(rnorm(100),rnorm(100,2))
out=cpt.np(x) # runs the ecdf changepoint method
plot(out) # plots the data with changepoints marked
cpts(out) # lists the changepoints identified

Alternatively, if you want a change in mean and are willing to make distributional assumptions the changepoint package contains the cpt.mean function or cpt.meanvar if the variance is changing too.

If you have dependence in the data then you just need to inflate the default penalty otherwise you get spurious changes that are just due to the dependence structure. For that you might want to use the CROPS (changepoints for a range of penalties) options available in both packages.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.