Hello, I am working on a small data set and trying to find values of Qmax
and Kl for the equation qe = (Qmax * Kl * ce) / (1 + 𝐾l* ce) I found my Qmax and Kl through the linear model butam now trying to find them through the "nls" function however an error comes up that I am unfamiliar with. I have the file loaded for reference. Any help is appreciated. Thank you. -Timothy ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. |
Your text has unreadable characters in it. Use plain text.
Also, your attachments are not coming through. Read the Posting Guide about attachments... best results are usually obtained by inserting the R code in the body of your email and not attaching anything. -- Sent from my phone. Please excuse my brevity. On December 19, 2017 2:13:03 PM PST, Timothy Axberg <[hidden email]> wrote: >Hello, I am working on a small data set and trying to find values of >Qmax >and Kl for the equation > >qe = (Qmax * Kl * ce) / (1 + 𝐾l* ce) > >I found my Qmax and Kl through the linear model butam now trying to >find >them through the "nls" function however an error comes up that I am >unfamiliar with. I have the file loaded for reference. Any help is >appreciated. Thank you. > >-Timothy >______________________________________________ >[hidden email] mailing list -- To UNSUBSCRIBE and more, see >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide >http://www.R-project.org/posting-guide.html >and provide commented, minimal, self-contained, reproducible code. ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. |
You also need to reply-all so the mailing list stays in the loop.
-- Sent from my phone. Please excuse my brevity. On December 19, 2017 4:00:29 PM PST, Timothy Axberg <[hidden email]> wrote: >Sorry about that. Here is the code typed directly on the email. > >qe = (Qmax * Kl * ce) / (1 + Kl * ce) > >##The data >ce <- c(15.17, 42.15, 69.12, 237.7, 419.77) >qe <- c(17.65, 30.07, 65.36, 81.7, 90.2) > >##The linearized data >celin <- 1/ce >qelin <- 1/qe > >plot(ce, qe, xlim = xlim, ylim = ylim) > >##The linear model >fit1 <- lm(qelin ~ celin) >intercept1 <- fit1$coefficients[1] >slope1 <- fit1$coeffecients[2] >summary(fit1) > >Qmax <- 1/intercept1 >Kl <- .735011*Qmax > >xlim <- range(ce, celin) >ylim <- range(qe, qelin) > >abline(lm(qelin ~ celin)) > >c <- seq(min(ce), max(ce)) >q <- (Qmax*Kl*c)/(1+(Kl*c)) > >lines(c, q) > > >##My attempt at the nonlinear regression >fit2 <- nls(qe ~ ((Qmax*Kl*ce)/(1+(Kl*ce))), start = list(Qmax = Qmax, >Kl = >Kl)) >results <- fit2$m$getpars() >Qmax2 <- fit2$m$getpars()[1] >Kl2 <- fit2$m$getpars()[2] >summary(fit2) > >-Timothy ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. |
Should I repost the question with reply-all?
On Tue, Dec 19, 2017 at 6:13 PM, Jeff Newmiller <[hidden email]> wrote: > You also need to reply-all so the mailing list stays in the loop. > -- > Sent from my phone. Please excuse my brevity. > > On December 19, 2017 4:00:29 PM PST, Timothy Axberg < > [hidden email]> wrote: > >Sorry about that. Here is the code typed directly on the email. > > > >qe = (Qmax * Kl * ce) / (1 + Kl * ce) > > > >##The data > >ce <- c(15.17, 42.15, 69.12, 237.7, 419.77) > >qe <- c(17.65, 30.07, 65.36, 81.7, 90.2) > > > >##The linearized data > >celin <- 1/ce > >qelin <- 1/qe > > > >plot(ce, qe, xlim = xlim, ylim = ylim) > > > >##The linear model > >fit1 <- lm(qelin ~ celin) > >intercept1 <- fit1$coefficients[1] > >slope1 <- fit1$coeffecients[2] > >summary(fit1) > > > >Qmax <- 1/intercept1 > >Kl <- .735011*Qmax > > > >xlim <- range(ce, celin) > >ylim <- range(qe, qelin) > > > >abline(lm(qelin ~ celin)) > > > >c <- seq(min(ce), max(ce)) > >q <- (Qmax*Kl*c)/(1+(Kl*c)) > > > >lines(c, q) > > > > > >##My attempt at the nonlinear regression > >fit2 <- nls(qe ~ ((Qmax*Kl*ce)/(1+(Kl*ce))), start = list(Qmax = Qmax, > >Kl = > >Kl)) > >results <- fit2$m$getpars() > >Qmax2 <- fit2$m$getpars()[1] > >Kl2 <- fit2$m$getpars()[2] > >summary(fit2) > > > >-Timothy > [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. |
G'day Timothy,
On Tue, 19 Dec 2017 18:28:00 -0600 Timothy Axberg <[hidden email]> wrote: > Should I repost the question with reply-all? Nope, we got all from Jeff's post. :) > On Tue, Dec 19, 2017 at 6:13 PM, Jeff Newmiller > <[hidden email]> wrote: > > > You also need to reply-all so the mailing list stays in the loop. > > -- > > Sent from my phone. Please excuse my brevity. > > > > On December 19, 2017 4:00:29 PM PST, Timothy Axberg < > > [hidden email]> wrote: > > >Sorry about that. Here is the code typed directly on the email. > > > > > >qe = (Qmax * Kl * ce) / (1 + Kl * ce) > > >##The linearized data > > >celin <- 1/ce > > >qelin <- 1/qe Plotting qelin against celin, I can see why you call this the linearized data. But fitting a linear model to these data obviously does not give you good starting values for nls(). Given your model equation, I would linearize the model to: qe = Qmax*KL * ce + KL * ce*qe and fit a non-intercept linear model to predict qe by ce and ce*qe. From this model I would then determine starting values for nls(). It seems to work with your data set: R> ce <- c(15.17, 42.15, 69.12, 237.7, 419.77) R> qe <- c(17.65, 30.07, 65.36, 81.7, 90.2) R> fit2 <- lm(qe ~ ce + I(ce*qe) - 1) R> summary(fit2) R> Kl <- - coef(fit2)[2] R> Qmax <- coef(fit2)[1]/Kl R> plot(ce, qe) R> c <- seq(min(ce), max(ce)) R> q <- (Qmax*Kl*c)/(1+(Kl*c)) R> lines(c, q) R> fit2 <- nls(qe ~ ((Qmax*Kl*ce)/(1+(Kl*ce))), start = list(Qmax = Qmax,Kl =Kl)) R> summary(fit2) Formula: qe ~ ((Qmax * Kl * ce)/(1 + (Kl * ce))) Parameters: Estimate Std. Error t value Pr(>|t|) Qmax 106.42602 12.82808 8.296 0.00367 ** Kl 0.01456 0.00543 2.681 0.07496 . --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 9.249 on 3 degrees of freedom Number of iterations to convergence: 2 Achieved convergence tolerance: 6.355e-06 HTH. Cheers, Berwin ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. |
Thank you! I didn't realize I wasn't linearizing it correctly. This was
very helpful. -Timothy On Tue, Dec 19, 2017 at 10:29 PM, Berwin A Turlach <[hidden email] > wrote: > G'day Timothy, > > On Tue, 19 Dec 2017 18:28:00 -0600 > Timothy Axberg <[hidden email]> wrote: > > > Should I repost the question with reply-all? > > Nope, we got all from Jeff's post. :) > > > On Tue, Dec 19, 2017 at 6:13 PM, Jeff Newmiller > > <[hidden email]> wrote: > > > > > You also need to reply-all so the mailing list stays in the loop. > > > -- > > > Sent from my phone. Please excuse my brevity. > > > > > > On December 19, 2017 4:00:29 PM PST, Timothy Axberg < > > > [hidden email]> wrote: > > > >Sorry about that. Here is the code typed directly on the email. > > > > > > > >qe = (Qmax * Kl * ce) / (1 + Kl * ce) > [...] > > > >##The linearized data > > > >celin <- 1/ce > > > >qelin <- 1/qe > > Plotting qelin against celin, I can see why you call this the > linearized data. But fitting a linear model to these data obviously > does not give you good starting values for nls(). > > Given your model equation, I would linearize the model to: > > qe = Qmax*KL * ce + KL * ce*qe > > and fit a non-intercept linear model to predict qe by ce and > ce*qe. From this model I would then determine starting values for > nls(). It seems to work with your data set: > > R> ce <- c(15.17, 42.15, 69.12, 237.7, 419.77) > R> qe <- c(17.65, 30.07, 65.36, 81.7, 90.2) > R> fit2 <- lm(qe ~ ce + I(ce*qe) - 1) > R> summary(fit2) > R> Kl <- - coef(fit2)[2] > R> Qmax <- coef(fit2)[1]/Kl > R> plot(ce, qe) > R> c <- seq(min(ce), max(ce)) > R> q <- (Qmax*Kl*c)/(1+(Kl*c)) > R> lines(c, q) > R> fit2 <- nls(qe ~ ((Qmax*Kl*ce)/(1+(Kl*ce))), start = list(Qmax = > Qmax,Kl =Kl)) > R> summary(fit2) > > Formula: qe ~ ((Qmax * Kl * ce)/(1 + (Kl * ce))) > > Parameters: > Estimate Std. Error t value Pr(>|t|) > Qmax 106.42602 12.82808 8.296 0.00367 ** > Kl 0.01456 0.00543 2.681 0.07496 . > --- > Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > > Residual standard error: 9.249 on 3 degrees of freedom > > Number of iterations to convergence: 2 > Achieved convergence tolerance: 6.355e-06 > > HTH. > > Cheers, > > Berwin > > [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. |
Free forum by Nabble | Edit this page |