curve-fitting

Goodness of fit functions in R

只愿长相守 提交于 2019-11-29 19:34:28
What functions do you use in R to fit a curve to your data and test how well that curve fits? What results are considered good? Dirk Eddelbuettel Just the first part of that question can fill entire books. Just some quick choices: lm() for standard linear models glm() for generalised linear models (eg for logistic regression) rlm() from package MASS for robust linear models lmrob() from package robustbase for robust linear models loess() for non-linear / non-parametric models Then there are domain-specific models as e.g. time series, micro-econometrics, mixed-effects and much more. Several of

fitting multivariate curve_fit in python

本小妞迷上赌 提交于 2019-11-29 16:46:39
问题 I'm trying to fit a simple function to two arrays of independent data in python. I understand that I need to bunch the data for my independent variables into one array, but something still seems to be wrong with the way I'm passing variables when I try to do the fit. (There are a couple previous posts related to this one, but they haven't been much help.) import numpy as np import matplotlib.pyplot as plt from scipy.optimize import curve_fit def fitFunc(x_3d, a, b, c, d): return a + b*x_3d[0,

How to fit a gaussian to a histogram in R? [duplicate]

一曲冷凌霜 提交于 2019-11-29 16:38:53
Possible Duplicate: Fitting a density curve to a histogram in R best fitting curve from plot in R I have a set of data that when plotted in a histogram is a Gaussian distribution. I have read the data in from a .csv file that looks like this: "values" 1.29989 1.15652 1.27818 1.19699 1.28243 1.19433 1.10991 ... using data<-read.csv("~/peak.csv") ... so I create a histogram using hist(data$values) . I want to be able to fit a Gaussian to this histogram and compare the fitted function's sigma and mean to the sigma and mean calculated from the data. Everywhere that I have looked mentions nls and

Curve fitting this data in R?

非 Y 不嫁゛ 提交于 2019-11-29 16:04:12
For a few days I've been working on this problem and I'm stuck ... I have performed a number of Monte Carlo simulations in R which gives an output y for each input x and there is clearly some simple relationship between x and y, so I want to identify the formula and its parameters. But I can't seem to get a good overall fit for both the 'Low x' and 'High x' series, e.g. using a logarithm like this: dat = data.frame(x=x, y=y) fit = nls(y~a*log10(x)+b, data=dat, start=list(a=-0.8,b=-2), trace=TRUE) I have also tried to fit (log10(x), 10^y) instead, which gives a good fit but the reverse

Forcing nls to fit a curve passing through a specified point

六眼飞鱼酱① 提交于 2019-11-29 15:52:14
I'm trying to fit a Boltzmann sigmoid 1/(1+exp((x-p1)/p2)) to this small experimental dataset: xdata <- c(-60,-50,-40,-30,-20,-10,-0,10) ydata <- c(0.04, 0.09, 0.38, 0.63, 0.79, 1, 0.83, 0.56) I know that it is pretty simple to do it. For example, using nls : fit <-nls(ydata ~ 1/(1+exp((xdata-p1)/p2)),start=list(p1=mean(xdata),p2=-5)) I get the following results: Formula: ydata ~ 1/(1 + exp((xdata - p1)/p2)) Parameters: Estimate Std. Error t value Pr(>|t|) p1 -33.671 4.755 -7.081 0.000398 *** p2 -10.336 4.312 -2.397 0.053490 . --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

scipy.optimize.curvefit: Asymmetric error in fit

陌路散爱 提交于 2019-11-29 15:25:34
I try to fit a function to my data using scipy.optimize.curvefit . Q=optimization.curve_fit(func,X,Y, x0,ERR) and it works well. However, now I am trying to use an asymmetric error and I have no idea how to do that - or even if it is possible. By asymmetric error I mean that the error is not for example: 3+-0.5 but 3 +0.6 -0.2 . So that ERR is an array with two columns. It would be great if somebody had an idea how to do that - or could me point to a different Python routine which might be able to do it. That a snippet of the code I am using - but I am not sure it makes it clearer: A=numpy

Fitting with constraints on derivative Python

佐手、 提交于 2019-11-29 12:51:17
While trying to create an optimization algorithm, I had to put constraints on the curve fitting of my set. Here is my problem, I have an array : Z = [10.3, 10, 10.2, ...] L = [0, 20, 40, ...] I need to find a function that fits Z with condition on slope which is the derivative of the function I'm looking for. Suppose f is my function, f should fit Z and have a condition on f its derivative, it shouldnt exceed a special value. Are there any libraries in python that can help me achieve this task ? The COBYLA minimzer can handle such problems. In the following example a polynomial of degree 3 is

What's the error of numpy.polyfit?

泪湿孤枕 提交于 2019-11-29 10:53:25
问题 I want to use numpy.polyfit for physical calculations, therefore I need the magnitude of the error. 回答1: If you specify full=True in your call to polyfit, it will include extra information: >>> x = np.arange(100) >>> y = x**2 + 3*x + 5 + np.random.rand(100) >>> np.polyfit(x, y, 2) array([ 0.99995888, 3.00221219, 5.56776641]) >>> np.polyfit(x, y, 2, full=True) (array([ 0.99995888, 3.00221219, 5.56776641]), # coefficients array([ 7.19260721]), # residuals 3, # rank array([ 11.87708199, 3

How can I get a cubic bezier curve closest to given points?

淺唱寂寞╮ 提交于 2019-11-29 08:06:20
问题 Given n points: p0, p1, p2, ..., pn; How can I get the point c1, c2 so that the cubic bezier curve defined by p0, c1, c2, pn closest to the given points? I tried least square method. I wrote this after I read the pdf document in http://www.mathworks.com/matlabcentral/fileexchange/15542-cubic-bezier-least-square-fitting. But I can't find a good t(i) function. using System; using System.Collections.Generic; using System.Linq; using System.Windows; namespace BezierFitting { class

How to properly fit a beta distribution in python?

故事扮演 提交于 2019-11-29 07:21:46
I am trying to get a correct way of fitting a beta distribution. It's not a real world problem i am just testing the effects of a few different methods, and in doing this something is puzzling me. Here is the python code I am working on, in which I tested 3 different approaches: 1>: fit using moments (sample mean and variance). 2>: fit by minimizing the negative log-likelihood (by using scipy.optimize.fmin()). 3>: simply call scipy.stats.beta.fit() from scipy.optimize import fmin from scipy.stats import beta from scipy.special import gamma as gammaf import matplotlib.pyplot as plt import numpy