nls

Nonlinear least square in r

流过昼夜 提交于 2020-01-17 05:31:08
问题 Check please, there is a good fit or not. I have two vectors here: x=c(30,110) y=c(0.000760289, 0.000800320, 0.000830345, 0.000840353, 0.000860370, 0.000910414, 0.000990490, 0.001090594, 0.001200721, 0.001350912, 0.001531172, 0.001751533, 0.001961923, 0.002192402, 0.002463031, 0.002793899, 0.003185067, 0.003636604, 0.004148594, 0.004721127, 0.005394524, 0.006168989, 0.007014544, 0.007870894, 0.008758242, 0.009656474, 0.010565620, 0.011485709, 0.012396520, 0.013308162, 0.014271353, 0.015326859

How to plot non-linear regression lines within groups and total data in ggplot2?

与世无争的帅哥 提交于 2020-01-15 05:38:30
问题 I have a simple data set with two continous variables (Vesicle and Cells), and a single grouping variable with two levels (HC and RA), simulated here: ###Simulate Vesicle variable### Vesicle.hc <- sort(runif(23, 0.98, 5)) #HC group Vesicle1.ra <- sort(runif(5, 0.98, 3)) #RA group Vesicle <- c(Vesicle.hc, Vesicle1.ra) #Combined ###Simulate Cells variable### z <- seq(23) Cells.hc <- (rnorm(23, 50 + 30 * z^(0.2), 8))*runif(1, 50000, 400000) #HC group Cells.ra <- c(8.36e6, 6.35e6, 1.287e7, 1

How can fit curve on this log data?

青春壹個敷衍的年華 提交于 2020-01-11 13:08:55
问题 I have a problem with a fit curve on this data: On x axes we have a data about wind intensity (m/s), on y axes we have log data (fish catch). I fitted a curve (nls model, Gaussian curve) only on data without logaritm, but when i tried on log data, R tell me: Error in nls(mean.w ~ k * exp(-1/2 * (x.wind - mu)^2/sigma^2), : singolar gradient The model is: mean.w ~ k * exp(-1/2 * (x.wind - mu)^2/sigma^2) , where k,mu and sigma are the parameters to estimate, and mean.w # is y axes (log fish

Exponential curve fitting with nls using data.table groups

不羁的心 提交于 2020-01-06 07:14:24
问题 I'd like to fit exponential curves to groups 1 & 2 in the data table shown below and obtain a new column containing the residual standard error corresponding to each group. The exponential curve should follow y=a*exp(b*x)+c ## Example data table DT <- data.table( x = c(1,2,3,4,5,6,7,8,1,2,3,4,5,6,7,8), y = c(15.4,16,16.4,17.7,20,23,27,35,25.4,26,26.4,27.7,30,33,37,45), groups = c(1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2) However, I only know how to fit nls curves and obtain the residual standard error

R script - least squares solution to the following [duplicate]

本小妞迷上赌 提交于 2020-01-04 13:23:21
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: Finding where two linear fits intersect in R Given some points on a graph (usually only about 6 or 7 points), I need to find a best fit solution where the solution consists of the following: Two linear lines The lines must intersect The intersection point (the x point) must lie between two values I specify (such as xLow and xHigh) How would I do this using nls (or something better?)? If there are multiple best

Visualizing multiple curves in ggplot from bootstrapping, curve fitting

时光总嘲笑我的痴心妄想 提交于 2020-01-01 18:15:27
问题 I have time series data that is well modeled using a sinusoidal curve. I'd like to visualize the uncertainty in the fitted model using bootstrapping. I adapted the approach from here. I am also interested in this approach too, using nlsBoot . I can get the first approach to run, but the resulting plot contains curves that are not continuous, but jagged. library(dplyr) library(broom) library(ggplot2) xdata <- c(-35.98, -34.74, -33.46, -32.04, -30.86, -29.64, -28.50, -27.29, -26.00, -24.77, -23

Visualizing multiple curves in ggplot from bootstrapping, curve fitting

試著忘記壹切 提交于 2020-01-01 18:15:13
问题 I have time series data that is well modeled using a sinusoidal curve. I'd like to visualize the uncertainty in the fitted model using bootstrapping. I adapted the approach from here. I am also interested in this approach too, using nlsBoot . I can get the first approach to run, but the resulting plot contains curves that are not continuous, but jagged. library(dplyr) library(broom) library(ggplot2) xdata <- c(-35.98, -34.74, -33.46, -32.04, -30.86, -29.64, -28.50, -27.29, -26.00, -24.77, -23

Can we make prediction with nlxb from nlmrt package?

我与影子孤独终老i 提交于 2019-12-31 05:25:09
问题 I'm asking this question because I couldn't figure it out why nlxb fitting function does not work with the predict() function. I have been looking around to solve this but so far no luck:( I use dplyr to group data and use do to fit each group using nlxb from nlmrt package. Here is my attempt set.seed(12345) set =rep(rep(c("1","2","3","4"),each=21),times=1) time=rep(c(10,seq(100,900,100),seq(1000,10000,1000),20000),times=1) value <- replicate(1,c(replicate(4,sort(10^runif(21,-6,-3),decreasing

R : catching errors in `nls`

喜夏-厌秋 提交于 2019-12-30 03:26:08
问题 I'm fitting some exponential data using nls . The code I'm using is: fit <- nls(y ~ expFit(times, A, tau, C), start = c(A=100, tau=-3, C=0)) expFit is defined as expFit <- function(t, A, tau, C) { expFit <- A*(exp(-t/tau))+C } This works well for most of my data, for which the starting parameters provided (100, -3 and 0) work well. Sometimes, though, I have data that doesn't go well with those parameters and I get errors from nls (e.g. "singular gradient" or things like that). How do I "catch

R ggplot2 exponential regression with R² and p

你说的曾经没有我的故事 提交于 2019-12-25 06:24:52
问题 I am trying to do a exponential regression in ggplot2. So first my skript: g <- ggplot(data, aes(x=datax, y=datay), color="black") + geom_point(shape=1) + stat_smooth(method = 'nls', formula = y~a*exp(b*x), aes(colour = 'Exponential'), se = FALSE) g <- g + theme_classic() g <- g + theme(panel.grid.major=element_blank()) g <- g + theme(panel.grid.minor=element_blank()) g <- g + theme(axis.line.x=element_line(color="black"), axis.line.y=element_line(color="black"), panel.border=element_blank(),