I would like to assess the fit a given curve with some data points by computing the (idelly, adjusted) R^2, using Matlab.
All the tutorials I could find online explain how to do this when the curve has been obtained directly from the data set, but in my case the curve has been determined independently and I need to compute R^2 as a measure of the fit to the new data set, which I'm using as a test.
Is there any routine in Matlab to do this?
Related
I'm dealing with CWT, and I have a big problem converting scales to frequencies. In the MAtlab Wavelet Tutorial they use this expression to convert scales to frequencies
But if i use the default function scal2freq I obtain different result.
I don't understand the role of the Morlet Fourier Factor
Thanks in advance
It is a pretty complicated concept, which I somewhat understand it. I'll write some points here so that you might figure it out yourself, rather easier.
A simple fact is that:
Scale is inversely proportional to frequency.
For example, imagine we have a 1-100 Hz range of frequencies in some time series data such as stock markets data or earthquake data. Scale is "supposed to be" the inverse of that. For instance, if scale would be in range of 1 to 100, we'd have had:
Scale(1/Hz) Frequency (Hz)
1 100
50 50
100 1
Therefore,
The frequency is not the real frequency of those time series data (e.g., stock market, earthquake) that we know of. They are only related, inversely.
And we can safely say that here we are calculating some "pseudo-frequencies", which MATLAB does that (by approximating that). You can read about the approximation process in the documentation in the section pseudo-frequencies:
MATlAB does calculate those pseudo-frequencies based on:
In wavelet analysis, the way to relate scales to frequencies is to determine the center frequency of the wavelet function:
which you can visually see in this image and of-course it would differ, when we would change the types of our function in the calculation. Thus, that center frequency will change everytime in our approximation process:
That "MorletFourierFactor" is a variable to approximate a constant so that when you would do the 1/scale, it would closely approximate those "pseudo-frequencies".
I thought this image about shifting (time axis) and scaling (frequency axis) might be a little helpful to look into as well:
The bottom line is that don't worry about pseudo-frequencies, you wouldn't probably need those. If you would want any frequency spectrum, you can likely go towards applying some of those frequency methods (such as Fast Fourier Transform) on whatever time series data that you have.
If you really really want to map that, you can also try to design some methods to approximate it yourself.
Source
Harvard Seismology
I have a set of data which has a long baseline, with noise fluctuating around 0 then a point where an exponential curve occurs.
I'm looking for some relatively simple code that finds the point where the exponential curve begins. I need it to do it automatically because it for 1000's of different curves. So I can't just find the value myself from the plot.
I have a model for what the fit should be after the 'zero point'
How could I do this, in a relatively simple operation?
Currently my code finds an average of the baseline noise and then says when it goes above this point, the curve has begun. However, this isn't accurate enough.
You could take all the data points that have y value larger than 10% of the maximal y value and fit them to an exponential function y=exp((x-a)/b). Take natural log of you data points y(i) and fit these data points to ln(y)=(x-a)/b and I would take a/b as the "zero point". Hope this helps but if you can upload part of the data I can write a simple code to test my proposed solution.
The documentation I am reading for curve fitting doesnt seem to be that complicated, but clearly I am doing something wrong.
Given x,y data, trying to fit a polynomial function of degree 3, the data points are seemingly ignored. Can someone explain both how to fix this, and what this curve is actually calculating, as opposed to what I think it should be calculating?
Data: http://pastebin.com/4EXu0FSv
You most likely are using the wrong regression model or interval (or points). Curve fitting is very very complex topic and can not be simply solved. Have a read of the Mathworks site about the curve fitting toolbox here .
However I would not be fitting a 3 order polynomial to this data. I would be more inclinded to fit positive reciprocal function - see if that gives you a better fit.
I have a set of reference data points to which I want to fit a sigmoidal curve. I can use the curve fitting tool of MATLAB to do this but I have a custom equation to fit to the data. The equation has 4-5 variables which I want to vary and then test for the goodness of fit.
I tried using the goodnessOfFitfunction for this. But it requires the test data and reference data matrices to be of the same size. The numbers of reference data points that I have are few (15-20) and the number of test points generated by using the custom equation is large.
Is there any other way by which I can check the goodness of fit of the curve? Or do I have find the test data points corresponding to the points in the reference data and then use the goodnessOfFit function (One problem with this approach is that I don't have the same resolution for the x axis in the test and reference data e.g. for a x-point 1.2368 in ref. data I have either 1.23 and 1.24 in my test data. I will have to round off the data and then calculate the fit).
do I have find the test data points corresponding to the points in the reference data and then use the goodnessOfFit function. I will have to round off the data and then calculate the fit).
Yes, buddy..! Seems like you have to do it in the hard way! :/
But instead of simply rounding off, you can find the two points in the test data just before and after the corresponding reference sample point. Then use linear interpolation to guess the value corresponding to the reference point.
Or easier, there is a resamplefunction in Matlab which would resample your test data to match your reference data. This would work if the reference data have a constant sample interval.
All the best!
I'm working on my thesis project on financial mathematics. One problem I'm having is that I want to find out if there is some correlation between a theoretical curve and scatter point data.
Here is the scatter data and the theoretical curve that I have.
Is there some easy way of doing this?
Bivariate correlation (usually Pearson correlation) is a statistic that measures linear dependence between two sets of data. The theoretical curve of your link does not seem to consist of discrete data points, therefore it is not possible to calculate correlation between it a and some set of data.
Depending on the model and the research question you have, you might be interested in analyzing the fit of your data to the model, using multivariate regression analysis or general[ized] linear model. These MATLAB commands could be useful: regress (multiple linear regression), regstats (regression diagnostics), glmfit (generalized linear model regression) and glmval (generalized linear model values).