How can I robustly smooth my time series data?

I have data like the following image, where the x-axis is the absolute elapsed time in hours (think calendar days; this plot goes over ~2.5 years), and the y-axis is the manually entered uptime of a machine in hours.

For my data processing, I need a very robust way of smoothing the data. The image below shows a black, dashed line, which is the best I can get with a "normal" GAM.

I am thinking of a GAM that minimizes the median residual or something. My ideal goal is to obtain something close to the manually drawn red line.

I have tried many smoothers (cubic polynomial, loess, GAM, Theil-Sen linear regression), but every one fails in some special cases of the hundreds of graphs I have.

What are other robust smoothers that I could apply here? Or are there other techniques I have completely missed so far?

• As a machine can't have negative uptime (can it in your context have 0 uptime?), a GAM (or any model) with a Gaussian distribution for the response conditional upon the covariates is unlikely to work well - you can see partly why in your figure; at well before zero on the x-axis, the response is predicted to be negative. Also, a GAM in the sense that I understand you use of the term isn't minimising the "median residual". If this was a Gaussian GAM then it is minimising the penalised sum of squared errors, so is just like a linear regression plus the extra penalty on wiggliness. Jun 8, 2017 at 15:33
• You will definitely want to include the known constraints: the curve must pass through the origin, and must be non-decreasing (i.e. $y_0=0$ and $y_{i+1}\geq{y_i}$). Jun 8, 2017 at 16:11
• It might sound obvious but if you have constraints on the values your response transforming your data in a domain where this restrictions are automatically met is a viable option. For instance why not take $log_{10}$ of your data? The back-transformation will immediately force the data to be positive. Similarly as @GeoMatt22 mentioned if you have a non-decreasing trend in your data, isotonic regression seems an obvious thing to try (Google smooth isotonic regression). BTW the grey dashed line "seems mostly OK" to me. Jul 1, 2017 at 12:21