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!
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.
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
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.