How to plot a best fit curve in Julia when the data is a time series? - plot

I'm trying to plot some measurements over time with a best-fit curve, using Julia's plotting tools. There's already a fairly good answer how to do this with a simple numeric data series:
Julia: How to find best fit curve / equation when I have a plot?
However, these tools (well - at least the Polynomials package) do not like being given Date values. I imagine some sort of conversion from Dates into a numeric value needs to be done, but I want the resulting plots to retain their scales in date units, which would need a conversion back again.
I suspect this is a fairly common problem and there must be an elegant way to solve it, but being new to Julia I would like to ask for some pointers to what a good solution looks like?
Thanks!

Related

How to frequency filter a time series in R

I'd like to know how to apply frequency filters to a time series in R and get the result back in the time domain (e.g. fourier transform -> get rid of certain frequencies -> inverse fourier transform) or a similar approach (there does not seem to be a suitable inverse function to fft). From what I have seen people recommend the signal package, but I don't seem to be able to get sensible results with this package. So to put an example. Let's say I have a simple monthy time series:
plot(log(AirPassengers))
Let's say I want to extract these seasonal fluctuations here using a band-pass filter (i.e. get rid of the trend and the small higher frequency movements). If someone could produce an R code do do this by fourier methods, preferably using a package function, and explain it that would be of great help to get me started.

Decomposition of additive time series

[Hey, I am sorry if this question might be too easy for this forum! My task was to decompose a time series to break it into the different components. Then plot it in R.
However, the correct solutions included the part that I uploaded as a picture. We are trying to identify the monthly data right? but why are we using the cbind and the data.frame function? than you very much in advance[enter image description here]1 ][2]

R equivalent to matlab griddata, scatteredInterpolant, and/or TriScatteredInterp

We do a lot of full field 3D numerical simulations (CFD, FEA, etc.). The solutions take a long time to run. We often interpolate from solutions rather than rerun every case. We also interpolate between multiple solutions, which leads to even higher dimensional interpolation (like adding time, so x,y,z,t,v).
Matlab does a great job of reading data V at irregular grid of X,Y,Z coordinates, and interpolating from V using griddata, scatterdInterpolan, and/or TriScatteredInterp. For a variety of reasons, I've switched to R. This remains one key area I've not been able to find as good R equivalent. 'akima' only does x,y,V (not, x,y,z,V, much less even higher dimensions like x,y,z,t,v).
The next best thing I've found has been 'krigging'. But krigging behaves more like model fitting and projection, and often does not behave well between irregular grid points. So it's not nearly as robust as simple direct linear interpolation.
Matlab has had griddata for several decades. It's hard to believe R doesn't have an equivalent out there. Any suggestions? Or is there at least a way to use krigging to yield effectively the same result as a direct linear interpolation?
Jonathan
You might start by looking at the package "tripack" to do Delaunay triangulation, which gives you the first step in duplicating scatteredInterpolant().
R interpp() is equivalent to MATLAB scatteredInterpolant().

Weird regression line in scatterplot in R

Hi guys so my problem is possibly either a stats or a programming issue. I have two xts time series of mostly overlapping time periods and I'm simply plotting a regression of their log differences:
logdiff <- merge.xts(diff(log(ts1)),diff(log(ts2)))
plot(logdiff[,1],logdiff[,2])
abline(lm(logdiff[,1]~logdiff[,2]),col=2)
which gives me this plot
So just on an intuitive level I would rather the regression line fit the wider range of data points even if this result its giving me is technically the correct one on a least squares basis. Is there any inbuilt capability to do this "broader regression" or do i have to resort to manual fudging?
I think you are plotting y as a function of x, but regressing x as a function of y.
Try abline(lm(logdiff[,2]~logdiff[,1]),col=2) -- and yes, using column names instead of indices is a good idea.

Best R package for doing Fourier Analysis for three dimensional function

I want to find a function that approximates a function that produces output that looks like:
Blue, Red and Green are the X, Y and Z space dimensions.
What R package should I use?
I realize this question is very old, but has it been resolved yet for you?
First the short answer: You should use
Library TuneR for the function periodogram()
Library strucchange for the function Wave() with which you build an object that will plot nicely
Considering your comment about losing information if you apply a fourier-transform on the 3 dimensions separately instead of, say, on the vector for each point in time: You will lose information anyway in the fourier-transform. The best you can do is make sure the axes are orthogonal. Looking at your data, even running the fourier over only one dimension will give you the major frequency without problems.

Resources