Hot answers tagged curve-fitting
14
It sounds like you want to perform multiple changepoint detection followed by independent smoothing within each segment. (Detection can be online or not, but your application is not likely to be online.) There's a lot of literature on this; Internet searches are fruitful.
DA Stephens wrote a useful introduction to Bayesian changepoint detection in 1994 ...
11
To solve your problem, a good approach is to define a probabilistic model that matches the assumptions about your dataset. In your case, you probably want a mixture of linear regression models. You can create a "mixture of regressors" model similar to a gaussian mixture model by associating different data points with different mixture components.
I have ...
9
It would be possible to create a dataset in such a way that the residuals from the linear model are orthogonal to the quadratic and cubic terms and in that case adding the terms would not change the fit to the model. However the probability of getting such a dataset in the real world is close enough to 0 that you will not likely ever see this happen with a ...
8
Yes and no. At the theoretical level, both cases can use similar techniques and frameworks (an excellent example being Gaussian process regression).
The critical difference is the assumptions used to prevent overfitting (regularization):
In the functional case, there is usually some assumption of smoothness, in other words, values occurring close to each ...
8
Since you know the density, you can just use fitdistr.
# Sample data
library(LaplacesDemon)
x <- rinvgamma(1000, 1,2)
library(MASS)
f <- function(x, rho, a, s)
1/(a*gamma(rho)) * (a / (x-s))^(rho+1) * exp( - a/(x-s) )
fitdistr( x, f, list(rho=1, a=1, s=0) )
8
Elsewhere in this thread, user1149913 provides great advice (define a probabilistic model) and code for a powerful approach (EM estimation). Two issues remain to be addressed:
How to cope with departures from the probabilistic model (which are very evident in the 2011-2012 data and somewhat evident in the undulations of the less-sloped points).
How to ...
8
See the nls() function. It has a self starting logistic curve model function via SSlogis(). E.g. from the ?nls help page
> library("nls")
> DNase1 <- subset(DNase, Run == 1)
>
> ## using a selfStart model
> fm1DNase1 <- nls(density ~ SSlogis(log(conc), Asym, xmid, scal),
+ DNase1)
I suggest you read the help ...
8
The methods we would use to fit this manually (that is, of Exploratory Data Analysis) can work remarkably well with such data.
I wish to reparameterize the model slightly in order to make its parameters positive:
$$y = a x - b / \sqrt{x}.$$
For a given $y$, let's assume there is a unique real $x$ satisfying this equation; call this $f(y; a,b)$ or, for ...
7
The root mean squared error and the likelihood are actually closely related. Say you have a dataset of $\lbrace x_i, z_i \rbrace$ pairs and you want to model their relationship using the model $f$. You decide to minimize the quadratic error
$$\sum_i \left(f(x_i) - z_i\right)^2$$
Isn't this choice totally arbitrary? Sure, you want to penalize estimates ...
7
RMS stands for the root mean square error. It's calculated in the following way.
First we calculate the residuals: -96.72, 265.77, -169.05
Next we calculate the squared residuals: -96.72$^2$, 265.77$^2$, -169.05$^2$
Then we sum and divide by $n-2=1$
Take the square root.
Further info
A residual is simply the $observed - fitted$. So when x = 35, the ...
7
Functional Data often involves different question. I've been reading Functional Data Analysis, Ramsey and Silverman, and they spend a lot of times discussing curve registration, warping functions, and estimating derivatives of curves. These tend to be very different questions than those asked by people interested in studying high-dimensional data.
7
I will assume the values of all the variables and constants are such that there won't be problems with obtaining square roots of negative numbers. Then
$$\frac{\sqrt{c_1 x + c_2 \exp(x)^y}}{\sqrt{\exp(x)^y}} + c_3 =\sqrt{c_2 + c_1 x \exp(-y x)} + c_3.$$
When $y \gt 0$ then eventually, for sufficiently large $x$, $\frac{c_1}{c_2} x \exp(-y x)$ gets small ...
7
Not sure if there'll be any other "ranty" responses, but heres mine.
Cross Validation is in no way "new". Additionally, Cross Validation is not used when analytic solutions are found. For example you don't use cross validation to estimate the betas, you use OLS or IRLS or some other "optimal" solution.
What I see as a glaringly obvious gap in the quote is ...
6
do it with koencker's broken line regression, see page 18 of this vignette
http://cran.r-project.org/web/packages/quantreg/vignettes/rq.pdf
In response to Whuber last comment:
This estimator is defined like this.
$x\in\mathbb{R}$, $x_{(i)}\geq x_{(i-1)}\;\forall i$,
$e_i:=y_{i}-\beta_{i}x_{(i)}-\beta_0$,
$z^+=\max(z,0)$, $z^-=\max(-z,0)$,
$\tau \in ...
6
A normal probability plot is an excellent way to compare an empirical distribution to a normal distribution. Its merits are that it clearly displays the nature of any deviations from normality: ideally, the points lie along the diagonal; vertical deviations from the diagonal depict deviations from normality. Its disadvantages are that many people do not ...
6
You might want to check out the free software called Eureqa. It has the specific aim of automating the process of finding both the functional form and the parameters of a given functional relationship.
If you are comparing models, with different numbers of parameters, you will generally want to use a measure of fit that penalises models with more ...
6
It's not a good idea to rescale the data in this ad hoc way, because it can result in an inferior fit (and ruins any chance of estimating the sampling variance of the scale parameter): just fit a scaled Beta distribution to the data themselves.
You do have to assign percentage points to the data; below I have used $p(i) = (i-1/2)/n$ for the $i^\text{th}$ ...
6
Here are some methods and associated R packages to solve this problem
Wavelet thresolding estimation in regression allows for discontonuities. You may use the package wavethresh in R.
A lot of tree based methods (not far from the idea of wavelet) are usefull when you have disconitnuities. Hence package treethresh, package tree !
In the familly of ...
6
That's the root mean square error (RMSE) of the regression.
$$RMSE = \sqrt{\frac{1}{n-k}\sum{(y_i-\hat{y_i})^2}},$$
where $y_i$ is the observed and $\hat{y_i}$ the fitted value for observation $i$, $n$ is the number of observations, and $k$ is the number of parameters fitted (including the constant).
I just tried fitting a straight line by simple linear ...
6
(As others have pointed out, a Weibull distribution is not likely to be an appropriate approximation when the data are integers only. The following is intended just to help you determine what that previous researcher did, rightly or wrongly.)
There are several alternative methods that are not affected by zeros in the data, such as using various method-of ...
5
The periodogram will estimate the periods. It will also handle noisy data and pick out multiple sinusoidal components of different period.
A quick and dirty Mathematica calculation is
data = N[Table[Sin[3.17*2*Pi*x/200], {x, 1, n}]];
welch = 1 - (2 (Range[n] - (n - 1)/2)/(n + 1))^2;
fData = Append[Abs[Fourier[welch data]]^2 / (Plus @@ (welch^2)), 0];
...
5
Does this make any sense? Partly.
What does he mean? Please ask him.
Do you have a clue - or perhaps even a name for the proposed method and some references?
Cross Validation. http://en.wikipedia.org/wiki/Cross-validation_(statistics)
Or did this guy find the holy grail nobody else understands? No.
He even says in this interview that his method ...
5
It seems to me you are actually looking for a regression models with re-descending loss function ("far away points are weighted less than close ones") loss function. Such loss functions --for example the Tukey biweight-- lead to highly non-convex optimization problems, meaning that there are, potentially, a finite but factorial-order increasing number of ...
5
The difference is basically the difference in the assumed distribution of the random component, and how the random component interacts with the underlying mean relationship.
Using nonlinear least squares effectively assumes the noise is additive, with constant variance (and LS is ML for normal errors).
The other two assume that the noise is multiplicative, ...
5
Everything can be done with polyfit function only. Read about its optional output parameters in
http://www.mathworks.nl/help/matlab/ref/polyfit.html
For instance:
[p,S,mu] = polyfit(x,y,n)
where mu is the two-element vector [μ1,μ2], where μ1=mean(x), μ2=std(x)
To compute error, you have to use another function taking output of polyfit:
[y,delta] = ...
4
The first thing to do, if possible, is to take care of the heteroscedasticity. Notice how the spread of the residuals consistently increases with the fit: in fact, the spread seems to increase almost quadratically with larger fit.
A standard cure is to return to the original response ($log(xy)$) and apply a strong transformation, such as a logarithm or ...
4
It's the RMS (root mean square) of the residuals of the linear regression.
In R:
> x <-c(35, 430, 656)
> y <- c(0, 4861, 7000)
> mod <- lm(y~x)
> mod
Call:
lm(formula = y ~ x)
Coefficients:
(Intercept) x
-301.88 11.39
> sqrt(sum(resid(mod)^2))
[1] 329.4998
4
I don’t really get what you mean with AGWN, is this simply that $n(t_i)$ are independent with $n(t_i) \sim N(0,\sigma^2)$?
The least squares estimator (which, as usual with a normal model, coincide with maximum likelihood estimator, see eg this answer) is easy to find with numerical methods, here is a piece of R code:
a <- 2; b <- 0.2; c <- -1
t ...
Only top voted, non community-wiki answers of a minimum length are eligible