Description Usage Arguments Value Author(s) See Also Examples
This function opens a interface, builted with
rpanel elements, designed for non linear regression models
fitting. Sliders allows the user control values used as start
values in the nls()
call, checkbox allows
select strata of the data to fit separed curves and more options
are available.
1 2 3 4 5 6 7 8 9 10 11 |
model |
a non linear model formula including variables and
parameters to passed to |
data |
a data frame with dependent and independent variables present in the model formula. |
start |
a named list with one item for each parameter. Each item
must vector with 2 (from, to) or 3 values (from, to, init) for
the |
subset |
an optional string indicating a grouping variable to fit separeted curves for each level. It must be a factor. |
xlab |
labels for the x axis. |
ylab |
labels for the y axis. |
... |
arguments passed to the plot function used to draw the
|
gpar |
a named list with graphical parameters for curve. The
|
extra |
a function of the model parameters that draw auxiliary graphical elements. For example, draw vertical and horizontal lines as references for model intercept and/or model asymptote. |
In fact none is returned by the function. There isn't a
return
, instead there is a invisible
at the end. On
the other hand, the model fit is assigned to the object with name
passed to the assign
argument.
Walmes Zeviani, walmes@ufpr.br.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | ## Not run:
#--------------------------------------------
# A simple linear regression.
# The model below is a linear model. You should fit in lm().
library(rpanel)
cars.fit <- rp.nls(model = dist ~ b0 + b1 * speed, data = cars,
start = list(b0 = c(-20, 20),
b1 = c(0, 2, 10)),
xlab = "Speed", ylab = "Distance")
summary(cars.fit)
confint(cars.fit)
f <- formula(cars.fit)
plot(dist ~ speed, data = cars)
with(as.list(coef(cars.fit)), {
eval(call("curve", f[[3]], add = TRUE,
xname = intersect(all.vars(f[-2]), names(cars))))
})
#--------------------------------------------
# A non linear regression.
data(turk0, package = "alr3")
str(turk0)
plot(Gain ~ A, data = turk0,
xlab = "Metionine", ylab = "Weight gain")
turk.fit <- rp.nls(model = Gain ~ Int + (Asy - Int) * A/(Half + A),
data = turk0,
start = list(Int = c(600, 650),
Asy = c(750, 850),
Half = c(0, 0.2)),
extra = function(Int, Asy, Half) {
abline(h = c(Asy, Int), v = Half,
col = "green")
},
xlab = "Metionine", ylab = "Weight gain")
summary(turk.fit)
confint(turk.fit)
f <- formula(turk.fit)
plot(Gain ~ A, data = turk0,
xlab = "Metionine", ylab = "Weight gain")
with(as.list(coef(turk.fit)), {
eval(call("curve", f[[3]], add = TRUE,
xname = intersect(all.vars(f[-2]), names(turk0))))
})
#--------------------------------------------
# A more interesting example.
library(lattice)
xyplot(rate ~ conc, groups = state, data = Puromycin,
type = c("p", "smooth"), auto.key = TRUE)
Puro.fit <- rp.nls(model = rate ~
Int + (Top - Int) * conc/(Half + conc),
data = Puromycin,
start = list(Int = c(20, 70),
Top = c(100, 200),
Half = c(0, 0.6)),
subset = "state",
gpar = list(try = list(col = 2, lty = 2),
fit = list(col = "blue", lwd = 1.5)),
# extra = function(Int, Top, Half) {
# abline(h = c(Int, Top), v = Half,
# col = 2, lty = 2)
# },
xlab = "Concentration", ylab = "Rate",
xlim = c(0, 1.2), ylim = c(40, 220))
length(Puro.fit)
sapply(Puro.fit, coef)
sapply(Puro.fit, logLik)
sapply(Puro.fit, deviance)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.