curve-fitting

ggplot2 stat_function with calculated argument for different data subset inside a facet_grid

白昼怎懂夜的黑 提交于 2019-12-03 08:21:16
I have a follow up question to how to pass fitdistr calculated args to stat_function (see here for context). My data frame is like that (see below for full data set): > str(small_data) 'data.frame': 1032 obs. of 3 variables: $ Exp: Factor w/ 6 levels "1L","2L","3L",..: 1 1 1 1 1 1 1 1 1 1 ... $ t : num 0 0 0 0 0 0 0 0 0 0 ... $ int: num 75.7 86.1 76.3 82.3 98.3 ... I would like to plot a facet_grid grouped by Exp and t showing the density histogram of int as well as plot the fitted log-normal distribution on it (lognormal line colored by t). I have tried the following: library(MASS) meanlog <-

Linear fitting in python with uncertainty in both x and y coordinates [closed]

旧巷老猫 提交于 2019-12-03 08:13:18
Hi I would like to ask my fellow python users how they perform their linear fitting. I have been searching for the last two weeks on methods/libraries to perform this task and I would like to share my experience: If you want to perform a linear fitting based on the least-squares method you have many options. For example you can find classes in both numpy and scipy. Myself I have opted by the one presented by linfit (which follows the design of the linfit function in IDL): http://nbviewer.ipython.org/github/djpine/linfit/blob/master/linfit.ipynb This method assumes you are introducing the

Python power law fit with upper limits & asymmetric errors in data using ODR

瘦欲@ 提交于 2019-12-03 07:55:33
I'm trying to fit some data to a power law using python. The problem is that some of my points are upper limits, which I don't know how to include in the fitting routine. In the data, I have put the upper limits as errors in y equal to 1, when the rest is much smaller. You can put this errors to 0 and change the uplims list generator, but then the fit is terrible. The code is the following: import numpy as np import matplotlib.pyplot as plt from scipy.odr import * # Initiate some data x = [1.73e-04, 5.21e-04, 1.57e-03, 4.71e-03, 1.41e-02, 4.25e-02, 1.28e-01, 3.84e-01, 1.15e+00] x_err = [1e-04,

Fitting a function in R

匆匆过客 提交于 2019-12-03 07:41:53
I have a few datapoints (x and y) that seem to have a logarithmic relationship. > mydata x y 1 0 123 2 2 116 3 4 113 4 15 100 5 48 87 6 75 84 7 122 77 > qplot(x, y, data=mydata, geom="line") Now I would like to find an underlying function that fits the graph and allows me to infer other datapoints (i.e. 3 or 82 ). I read about lm and nls but I'm not getting anywhere really. At first, I created a function of which I thought it resembled the plot the most: f <- function(x, a, b) { a * exp(b *-x) } x <- seq(0:100) y <- f(seq(0:100), 1,1) qplot(x,y, geom="line") Afterwards, I tried to generate a

How to determine the uncertainty of fit parameters with Python?

别等时光非礼了梦想. 提交于 2019-12-03 06:02:24
I have the following data for x and y: x y 1.71 0.0 1.76 5.0 1.81 10.0 1.86 15.0 1.93 20.0 2.01 25.0 2.09 30.0 2.20 35.0 2.32 40.0 2.47 45.0 2.65 50.0 2.87 55.0 3.16 60.0 3.53 65.0 4.02 70.0 4.69 75.0 5.64 80.0 7.07 85.0 9.35 90.0 13.34 95.0 21.43 100.0 For the above data, I am trying to fit the data in the form: However, there are certain uncertainties associated with x and y, where x has uncertainty of 50% of x and y has a fixed uncertainty. I am trying to determine the uncertainty in the fit parameters with this uncertainties package . But, I am having issues with curve fitting with scipy

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

孤街醉人 提交于 2019-12-03 05:13:31
问题 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 *

Curve fitting unsorted points on a plane

喜你入骨 提交于 2019-12-03 04:25:15
Question: How do you fit a curve to points on a plane if they aren't single valued? For the example shown, how would one fit a curve (like the black one) to the noisy blue data? It's similar to spline smoothing, but I don't know the order of the data. Matlab would be preferred, but pseudocode is fine. Or a pointer to what the correct terminology for this problem is would be great. Thanks Your data look like a two-dimensional parametric plot of (x,y) as a function of some underlying parameter t . As such, it may be possible to do a least-squares fit of x(t) and y(t) if you can come up with a

Sine curve fit using lm and nls in R

牧云@^-^@ 提交于 2019-12-03 04:02:42
I am a beginner in curve fitting and several posts on Stackoverflow really helped me. I tried to fit a sine curve to my data using lm and nls but both methods show a strange fit as shown below. Could anyone point out where I went wrong. I would suspect something to do with time but could not get it right. My data can be accessed from here . data <- read.table(file="900days.txt", header=TRUE, sep="") time<-data$time temperature<-data$temperature #lm fitting xc<-cos(2*pi*time/366) xs<-sin(2*pi*time/366) fit.lm<-lm(temperature~xc+xs) summary(fit.lm) plot(temp~time, data=data, xlim=c(1, 900)) par

How can I perform a least-squares fitting over multiple data sets fast?

末鹿安然 提交于 2019-12-03 02:51:57
问题 I am trying to make a gaussian fit over many data points. E.g. I have a 256 x 262144 array of data. Where the 256 points need to be fitted to a gaussian distribution, and I need 262144 of them. Sometimes the peak of the gaussian distribution is outside the data-range, so to get an accurate mean result curve-fitting is the best approach. Even if the peak is inside the range, curve-fitting gives a better sigma because other data is not in the range. I have this working for one data point, using

How to fit more than one line to data points

穿精又带淫゛_ 提交于 2019-12-03 02:37:45
I am trying to fit more than one line to a list of points in 2D. My points are quite low in number (16 or 32). These points are coming from a simulated environment of a robot with laser range finders attached to its side. If the points lie on a line it means that they detected a wall , if not, it means they detected an obstacle . I am trying to detect the walls and calculate their intersection, and for this I thought the best idea is to fit lines on the dataset. Fitting one line to a set of points is not a problem, if we know all those points line on or around a line. My problem is that I don