model-fitting

trying to display original and fitted data (nls + dnorm) with ggplot2's geom_smooth()

僤鯓⒐⒋嵵緔 提交于 2019-12-02 18:29:19
I am exploring some data, so the first thing I wanted to do was try to fit a normal (Gaussian) distribution to it. This is my first time trying this in R, so I'm taking it one step at a time. First I pre-binned my data: myhist = data.frame(size = 10:27, counts = c(1L, 3L, 5L, 6L, 9L, 14L, 13L, 23L, 31L, 40L, 42L, 22L, 14L, 7L, 4L, 2L, 2L, 1L) ) qplot(x=size, y=counts, data=myhist) Since I want counts, I need to add a normalization factor (N) to scale up the density: fit = nls(counts ~ N * dnorm(size, m, s), data=myhist, start=c(m=20, s=5, N=sum(myhist$counts)) ) Then I create the fitted data

How to Fit to The Outer Shell of a Function

十年热恋 提交于 2019-12-02 13:55:26
问题 I am trying to make a gaussian fit on a function that is messy. I want to only fit the exterior outer shell (these are not just the max values at each x, because some of the max values will be too low too, because the sample size is low). from scipy.optimize import curve_fit def Gauss(x, a, x0, sigma, offset): return a * np.exp(-np.power(x - x0,2) / (2 * np.power(sigma,2))) + offset def fitNormal(x, y): popt, pcov = curve_fit(Gauss, x, y, p0=[np.max(y), np.median(x), np.std(x), np.min(y)])

Pass Pandas DataFrame to Scipy.optimize.curve_fit

♀尐吖头ヾ 提交于 2019-12-02 07:20:35
问题 I'd like to know the best way to use Scipy to fit Pandas DataFrame columns. If I have a data table (Pandas DataFrame) with columns ( A , B , C , D and Z_real ) where Z depends on A, B, C and D, I want to fit a function of each DataFrame row (Series) which makes a prediction for Z ( Z_pred ). The signature of each function to fit is func(series, param_1, param_2...) where series is the Pandas Series corresponding to each row of the DataFrame. I use the Pandas Series so that different functions

How to Fit to The Outer Shell of a Function

拟墨画扇 提交于 2019-12-02 06:35:35
I am trying to make a gaussian fit on a function that is messy. I want to only fit the exterior outer shell (these are not just the max values at each x, because some of the max values will be too low too, because the sample size is low). from scipy.optimize import curve_fit def Gauss(x, a, x0, sigma, offset): return a * np.exp(-np.power(x - x0,2) / (2 * np.power(sigma,2))) + offset def fitNormal(x, y): popt, pcov = curve_fit(Gauss, x, y, p0=[np.max(y), np.median(x), np.std(x), np.min(y)]) return popt plt.plot(xPlot,yPlot, 'k.') plt.xlabel('x') plt.ylabel('y') plt.title('Y(x)') x,y = xPlot

Pass Pandas DataFrame to Scipy.optimize.curve_fit

六眼飞鱼酱① 提交于 2019-12-02 04:52:21
I'd like to know the best way to use Scipy to fit Pandas DataFrame columns. If I have a data table (Pandas DataFrame) with columns ( A , B , C , D and Z_real ) where Z depends on A, B, C and D, I want to fit a function of each DataFrame row (Series) which makes a prediction for Z ( Z_pred ). The signature of each function to fit is func(series, param_1, param_2...) where series is the Pandas Series corresponding to each row of the DataFrame. I use the Pandas Series so that different functions can use different combinations of columns. I've tried passing the DataFrame to scipy.optimize.curve

How to implement automatic model determination and two state model fitting in python?

纵然是瞬间 提交于 2019-12-02 03:31:54
问题 Currently, I've been doing model fitting in Prism manually for all my data. It's quite tedious and time consuming. I wonder if there is any way to improve the efficiency in data analysis. I'm familiar with Python so I'd like to start with python to think of a better workflow. Your help is much appreciated. Two questions: How to do two state model fitting in python (figure 1)? In my case, it will has an initial linear increase followed by horizontal plateau state. I wish to the way of

Using R to fit a curve to a dataset using a specific equation

 ̄綄美尐妖づ 提交于 2019-12-02 03:25:25
I am using R. I would like to use a specific equation to fit a curve to one of my data sets (attached) > dput(data) structure(list(Gossypol = c(1036.331811, 4171.427741, 6039.995102, 5909.068158, 4140.242559, 4854.985845, 6982.035521, 6132.876396, 948.2418407, 3618.448997, 3130.376482, 5113.942098, 1180.171957, 1500.863038, 4576.787021, 5629.979049, 3378.151945, 3589.187889, 2508.417927, 1989.576826, 5972.926124, 2867.610671, 450.7205451, 1120.955, 3470.09352, 3575.043632, 2952.931863, 349.0864019, 1013.807628, 910.8879471, 3743.331903, 3350.203452, 592.3403778, 1517.045807, 1504.491931, 3736

Fitting a 3 parameter Weibull distribution

百般思念 提交于 2019-11-30 14:01:56
问题 I have been doing some data analysis in R and I am trying to figure out how to fit my data to a 3 parameter Weibull distribution. I found how to do it with a 2 parameter Weibull but have come up short in finding how to do it with a 3 parameter. Here is how I fit the data using the fitdistr function from the MASS package: y <- fitdistr(x[[6]], 'weibull') x[[6]] is a subset of my data and y is where I am storing the result of the fitting. 回答1: First, you might want to look at FAdist package.

Fitting a 3 parameter Weibull distribution

試著忘記壹切 提交于 2019-11-30 09:31:21
I have been doing some data analysis in R and I am trying to figure out how to fit my data to a 3 parameter Weibull distribution. I found how to do it with a 2 parameter Weibull but have come up short in finding how to do it with a 3 parameter. Here is how I fit the data using the fitdistr function from the MASS package: y <- fitdistr(x[[6]], 'weibull') x[[6]] is a subset of my data and y is where I am storing the result of the fitting. First, you might want to look at FAdist package . However, that is not so hard to go from rweibull3 to rweibull : > rweibull3 function (n, shape, scale = 1,

Finding the best trade-off point on a curve

∥☆過路亽.° 提交于 2019-11-26 18:24:53
Say I had some data, for which I want to fit a parametrized model over it. My goal is to find the best value for this model parameter. I'm doing model selection using a AIC / BIC / MDL type of criterion which rewards models with low error but also penalizes models with high complexity (we're seeking the simplest yet most convincing explanation for this data so to speak, a la Occam's razor ). Following the above, this is an example of the sort of things I get for three different criteria (two are to be minimized, and one to be maximized): Visually you can easily see the elbow shape and you