lbbe-software / nlstools

Tools for Nonlinear Regression Analysis
7 stars 1 forks source link

plotfit() returning error on data with multiple independent variables #8

Open wolterstori opened 2 weeks ago

wolterstori commented 2 weeks ago

Hi,

We are working on a non-linear regression using estimated vs observed chlorophyll and found the nlstools package... everything else has worked except plotfit(), where I received the following error:

formulaExp <- as.formula(Estimated ~ ((Rrs704/Rrs665) (a + (1.61 Rrs740)/(0.082 - 0.6 Rrs740)) - b - (1.61 Rrs740)/(0.082 - 0.6 * Rrs740)^d)/c) preview(formulaExp, data = Gons740, start = list(a = 0.70, b = 0.40, c = 0.016, d = 1.06)) Chl.nls1<- nls(formulaExp, start = list(a = 0.70, b = 0.40, c = 0.016, d = 1.06), data = Gons740) overview(Chl.nls1) plotfit(Chl.nls1, smooth = FALSE) Error in (function (formula, data = NULL, subset = NULL, na.action, drop.unused.levels = FALSE, : invalid type (list) for variable 'd[, vardep]'

I ran through a couple examples as well... first using the O2K dataset (no issues) and the Michaelis Menten vmkmki dataset. I received the same error on the vmkmki dataset. View(vmkmki)

def.par <- par(no.readonly = TRUE) par(mfrow = c(2,2)) nls2_c <- nls(compet_mich, vmkmki, list(Km=1,Vmax=20,Ki=0.5)) plotfit(nls2_c, variable=1) Error in (function (formula, data = NULL, subset = NULL, na.action, drop.unused.levels = FALSE, : invalid type (list) for variable 'd[, vardep]'

Any guidance you can offer would be much appreciated.

wolterstori commented 2 weeks ago

Attached is the data file we are using Gons740.csv

Florent-Baty commented 1 week ago

Please have a look at the help from the function plotfit, more specifically the argument 'variable'. Whenever you have multiple independent variable, you should specify the index of the column corresponding to the variable you want to plot against the predicted values. For example in your data set, if you want to visualize the variable Rrs704 (3rd column of your data set), please use the following:

plotfit(Chl.nls1, smooth=FALSE, variable=3)