Direct method to remove the trend of spatio  temporal data througth median polish.
1  removetrendMPst(MPST,eps=0.01, maxiter=10L)

MPST 
object of class 
eps 
real number greater than 
maxiter 
the maximum number of iterations, default 10. 
Following the Berke's approach (Berke, 2001) to remove spatial trend, Martinez et al.(2017) used a structure of four dimensions to apply median polish tecnique.
For data ≤ft\{Y(\mathbf{s}_{abc},t), a=1,...,U; b=1,...,V; c=1,...,W, t=1,...,n \right\} , a spatial and temporal process is given by:
Y(\mathbf{s}_{abc},t)= μ_{y}(\mathbf{s}_{abc},t) + δ _{abct}
where
μ _{y}(\mathbf{s}_{abc},t)= μ +α _{a} + β _{b} + ξ _{c} + τ _{t}
and δ _{abct} is a fluctuation arising from natural variability and from the measurement process. Additionally, μ is an overall mean, α_{a} is the ath row effect, β_{b} is the effect bth column effect, ξ_{c} is the cth layer effect and τ _{t} is the tth time effect.
data.frame with the following fields:
ET 
indicate the time of a observation. 
x 
spatial coordinate x. 
y 
spatial coordinate y. 
z 
spatial coordinate z. 
Trend 
trend calculated through median polish space  time. 
Value 
observed values. 
Residual 
Residual = ValueTrend. 
Martínez, W. A., Melo, C. E., & Melo, O. O. (2017). Median Polish Kriging for space–time analysis of precipitation Spatial Statistics, 19, 120. [link]
Berke, O. (2001). Modified median polish kriging and its application to the wolfcamp  aquifer data. Environmetrics, 12(8):731748.[link]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15  ## Not run:
library(zoo)
data(Metadb)
#records of monthly precipitation from january 2007 to january 2010
Metadb<Metadb[,c(1:4,89:125)]
x<matrix(0,1,37)
for(i in 1:37){
x[,i] < 2007 + (seq(0, 36)/12)[i]
}
x<as.Date (as.yearmon(x), frac = 1)
time = as.POSIXct(x, tz = "GMT")
MPST<ConstructMPst(Metadb[,c(1:4)],time,pts=Metadb[,2:4],Delta=c(7,6,5))
residual<removetrendMPst(MPST,eps=0.01, maxiter=2)
## End(Not run)

Questions? Problems? Suggestions? Tweet to @rdrrHQ or email at ian@mutexlabs.com.
Please suggest features or report bugs with the GitHub issue tracker.
All documentation is copyright its authors; we didn't write any of that.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.