Fit Function to Data via Nonlinear Regression
Fit predefined functions to data via nonlinear least squares using Levenberg-Marquardt
algorithm via nlsLM
.
fitFunction( dataset = cs.in.dataset(), preds = cs.in.predictors(), resps = cs.in.responses(), groups = cs.in.groupvars(), auxs = cs.in.auxiliaries(), scriptvars = cs.in.scriptvars(), return.results = FALSE, ... )
dataset |
[ |
preds |
[ |
resps |
[ |
groups |
[ |
auxs |
[ |
scriptvars |
[ |
return.results |
[ |
... |
[ANY] |
The following script variables are summarized in scriptvars
list:
[character(1)
]
Function selection for fitting data. It is possible to choose a predefined model, or
compose a model manually by selecting User Defined
.
Default is User Defined
[character(1)
]
Required if math.fun
is set to User Defined
.
Valid R formula
for the right hand side (predictors) of the model equation.
[character(1)
]
Required if math.fun
is set to User Defined
.
Valid R formula
for the left hand side (response) of the model equation.
[character(1)
]
Optional if math.fun
is set to User Defined
.
Specifies minimum and maximum value for function math.fun
as a comma separated list
of min
and max
.
It is possible to assign variables, e.g. min=a
, which need start values in
start.vals
, as well as real numbers, e.g. min=4.5
, with a period as decimal
separator.
[character(1)
]
Required if math.fun
is set to User Defined
.
Specify starting values for all terms of the right hand side as a comma separated list
with a period as decimal separator.
[character(1)
]
Select a weighting variable from the auxiliary variables.
Maximum number of iterations.
For details see link[minpack.lm]{nls.lm.control}
Maximum relative error desired in the sum of squares. If 0
,
the default is used.
For details see link[minpack.lm]{nls.lm.control}
Logical [TRUE
] invisibly and outputs to Cornerstone or,
if return.results = TRUE
, list
of
resulting data.frame
objects:
coeff |
Estimated coefficients and standard errors for each group.
Convergence information is available for every group (for details see
|
vcov |
Variance-Covariance matrix of the main coefficients for the fitted model of each
group (for details see |
predictions |
Dataset to brush with predictions and residuals added to original values and groups, if available. |
# Generate data from logistic function: fun = function(x, a, b, c, d, sigma = 1) { a+(b-a) / (1+exp(-d*(x-c))) + rnorm(length(x), sd = sigma) } library(data.table) dt = data.table( x1 = sample(seq(-10, 10, length.out = 100)) , group1 = sample(x = c("A", "B"), replace = TRUE, size = 100) ) dt[group1 == "A", y1 := fun(x1, 1, 10, 1, 0.6, 0.1)] dt[group1 == "B", y1 := fun(x1, 8, 2, -1, 0.3, 0.1)] # Set script variables scriptvars = list(math.fun = "Logistic", resp.frml = "", preds.frml = "", limits = "" , start.vals = "", weights = "", max.iter = 50, max.ftol = 0 ) # Fit the logistic function: res = fitFunction(dt, "x1", "y1", "group1", character(0), scriptvars, TRUE) # Show estimated coefficients: res$coeff # Variance-Covariance matrix: res$vcov # Plot fitted vs. residuals: plot(res$predictions$Fitted, res$predictions$Residuals)
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.