[R] nls and factor
Christian Ritz
ritz at kvl.dk
Wed Apr 26 15:57:45 CEST 2006
Hi Manuel,
an alternative to the approach pointed out by Prof. Ripley is to use
the package 'drc' which allows one or more parameters in a non-linear
regression model to depend on a factor.
You will need the latest version available at www.bioassay.dk (an older
version is available on CRAN).
Bconc <- runif(30,0.1,10)
Aconc <- runif(30,0.1,10)
At <- runif(30,1,30)
Bt <- runif(30,1,30)
BKm <- 1
AKm <- 0
EBoth <- -0.41
yB <- 100*exp(EBoth*Bt)*Bconc/(BKm+Bconc)+rnorm(30,0,1)
yA <- 75*exp(EBoth*At)*Aconc/(AKm+Aconc)+rnorm(30,0,1)
## Constructing the dataset
tvalues <- c(At, Bt)
conc <- c(Aconc, Bconc)
yfactor <- factor(rep(c("A", "B"), c(30, 30)))
y <- c(yA, yB)
## Defining the non-linear function
twodimMM <- function()
{
fct <- function(x, parm)
{
parm[, 1]*exp(parm[, 2]*x[, 1])*x[, 2]/(parm[, 3] + x[, 2])
}
ssfct <- function(dataset) # a very simple self starter function
{
return(c(90, -0.5, 0.8))
}
names <- c("lev", "Ev", "km") # parameter names
return(list(fct=fct, ssfct=ssfct, names=names))
}
library(drc)
model1 <- multdrc(y~cbind(tvalues,conc), yfactor, fct=twodimMM())
summary(model1)
## Collapsing the Ev parameters into a single parameter
model2 <- multdrc(y~cbind(tvalues,conc), yfactor,
collapse=data.frame(yfactor,1,yfactor), fct=twodimMM())
anova(model2, model1) # model reduction is insignificant
summary(model2)
Christian
More information about the R-help
mailing list