# Tag Info

47

$R^2$ can be negative, it just means that: The model fits your data very badly You did not set an intercept To the people saying that $R^2$ is between 0 and 1, this is not the case. While a negative value for something with the word 'squared' in it might sound like it breaks the rules of maths, it can happen in an $R^2$ model without an intercept. To ...

30

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 ...

25

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 ...

23

I doubt that there is a clear and consistent distinction across statistically minded sciences and fields between regression and curve-fitting. Regression without qualification implies linear regression and least-squares estimation. That doesn't rule out other or broader senses: indeed once you allow logit, Poisson, negative binomial regression, etc., etc. ...

23

Fitting data to an equation without free parameters First, let's clarify what it means "to see how well my data fits to the equation" when you have a fixed equation as in your original question. You have data on $x$ and $y$, and your equation: $$y=(3.5-(x/10))(x/25)^{5/2}$$ has no free parameters. Here's a plot; data points are circles, the equation a solid ...

21

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 ...

18

This is a well known issue with high-order polynomials, known as Runge's phenomenon. Numerically it is associated with ill-conditioning of the Vandermonde matrix, which makes the coefficients very sensitive to small variations in the data and/or roundoff in the computations (i.e. the model is not stably identifiable). See also this answer on the SciComp SE. ...

15

I found this question linked on another question. I actually did academic research on this kind of problem. Please check my answer "Least square root" fitting? A fitting method with multiple minima for more details. whuber's Hough transform based approach is a very good solution for simple scenarios as the one you gave. I worked on scenarios with ...

15

Which model is appropriate depends on how variation around the mean comes into the observations. It may well come in multiplicatively or additively ... or in some other way. There can even be several sources of this variation, some which may enter multiplicatively and some which enter additively and some in ways that can't really be characterized as either. ...

15

Just to elaborate on my comment, here's an example of how your apparent pattern could be an artifact caused by the distribution of data along the x-axis. I generated 100,000 data points. They're normally distributed in the x-axis ($\mu = 2500, \sigma =600$) and exponentially distributed in the y-axis ($\lambda = 1$). Following the "visual envelope" of the ...

15

(Edited taking into account comments below. Thanks to @BenBolker & @WeiwenNg for helpful input.) Fit a fractional logistic regression to the data. It is well suited to percentage data that is bounded between 0 and 100% and is well-justified theoretically in many areas of biology. Note that you might have to divide all values by 100 to fit it, since ...

14

Your question is very broad. There are many ways to do this, even without assuming a specific function. For the following I assume that you have a good reason to use the Gompertz model. First let's fit the model: y <- c(0.5,3.0,22.2,46.0,77.3,97.0,98.9,100.0) x <- seq_along(y) plot(x, y) fit <- nls(y ~ SSgompertz(x, Asym, b2, b3), data = data....

13

There are many ways to smooth. Depending on how much effort you're prepared to go to, any of can be done in matlab (and probably already exist somewhere) and Excel (but you might have to do them yourself). [If you were asking about R I'd show you three or four ways you might smooth data.] That "smooth approximation" in the image just looks quadratic to me, ...

12

I think it will be helpful to separate the question into two parts: What is the functional form of your empirical distribution? and What does that functional form imply about the generating process in your network? The first question is a statistics question. If you've applied the methods of Clauset et al. for fitting the power-law distribution and those ...

12

This isn't a different answer from @mkt but graphs in particular won't fit into a comment. I first fit a logistic curve in Stata (after logging the predictor) to all data and get this graph An equation is 100 invlogit(-4.192654 + 1.880951 log10(Copies)) Now I fit curves separately for each virus in the simplest scenario of virus defining an indicator ...

11

In my opinion, it's a good strategy to transform your data before performing linear regression model as your data show good log relation: > #generating the data > n=500 > x <- 1:n > set.seed(10) > y <- 1*log(x)-6+rnorm(n) > > #plot the data > plot(y~x) > > #fit log model > fit <- lm(y~log(x)) > #Results of the ...

11

What does the science behind the data suggest? Yes, you can fit many different models including polynomials, splines, trigonometric functions, non-parametric smoothers, etc. But what is most important is what make sense based on the science behind the data (having fancy computers does not excuse us from understanding where our data comes from). What do ...

10

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 ...

10

Here's some pseudocode to do it. Of course, it depends on the error structure you choose. You don't need the stats models to do it, because Scipy has an minimizer built-in. The minimizer probably doesn't give you CIs though, like mle2 will. There may be another minimizer that will profile your parameters, but I don't know of one on the top of my head. ...

9

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) )

9

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 least squares is maximum likelihood for normal errors). The other two assume that ...

9

I had the same question a little while ago. This is what I found: Fox and Weisberg wrote a great supplemental article using the nls function (both with and without the self-starting option mentioned by Gavin). It can be found here: http://socserv.mcmaster.ca/jfox/Books/Companion/appendix/Appendix-Nonlinear-Regression.pdf From that article, I ended up ...

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 ...

9

Because brightness is a response with independent random error and it is expected to taper off with distance from the optimal point according to a Gaussian function, a quick nonlinear regression ought to do a good job. The model is $$y = b + a \exp\left(-\frac{1}{2}\left(\frac{x-m}{s}\right)^2\right) + \varepsilon$$ where $\varepsilon$ represents the ...

9

Here is a quick and dirty idea based on @alex's suggestion. #simulated data set.seed(100) x <- sort(exp(rnorm(1000, sd=0.6))) y <- ecdf(x)(x) It looks a little bit like your data. The idea is now to look at the derivative and try to see where it is biggest. This should be the part of your curve where it is straightest, because of it being an S-shape. ...

9

This kind of wild fluctuation arises from floating point rounding errors in the calculations. The hazard function of a $\Gamma(a,1)$ distribution, with shape parameter $a$ and scale parameter $1$, equals $$H(x; a) = \frac{x^{a-1}\exp(-x)}{\int_x^\infty t^{a-1} \exp(-t) dt }.$$ The maximum requested in the question is also the limiting value as $x\to\infty$...

9

Neither answer so far is entirely correct, so I will try to give my understanding of R-Squared. I have given a more detailed explanation of this on my blog post here "What is R-Squared" Sum Squared Error The objective of ordinary least squared regression is to get a line which minimized the sum squared error. The default line with minimum sum squared ...

9

The answer is yes, provided the data satisfy obvious consistency requirements. The argument is straightforward, based on a simple construction, but it requires some setting up. It comes down to an intuitively appealing fact: increasing the parameter $a$ in a Beta$(a,b)$ distribution increases the value of its density (PDF) more for larger $x$ than smaller \$...

9

"If all you have is a hammer, everything looks like a nail." The dataset you have is small, possibly underrepresented, and of unknown quality, since it is argued that many cases could have not been diagnosed. You observe an exponential growth, a common phenomena in many natural and artificial processes. The curve fits well, but I'd bet that other similar ...

Only top voted, non community-wiki answers of a minimum length are eligible