fitHillModel: Fit a Hill dose response model to data

View source: R/fitHillModel.R

fitHillModelR Documentation

Fit a Hill dose response model to data

Description

This function uses the R stats function optim to fit a Hill dose response model to a given set of dose and response values. Four different model settings are allowed, in which the minimal and maximal effects are either fixed at a provided value or allowed to be fit to the data.

Usage

fitHillModel(
  formula,
  data,
  model,
  weights = NULL,
  start = NULL,
  direction = 0,
  lower = NULL,
  upper = NULL
)

Arguments

formula

Either an object of class formula such as would be provided to a modeling function like lm(), or a numeric vector of concentration values (including 0 or Inf)

data

If forumula is a symbolic formula, a data frame containing the specified values. If formula is a numeric vector of concentrations, a numeric vector of response values

model

A vector of values between 1 and 4, specifying the precise model to be fit. The values correspond to the four parameters of the Hill model: dose of median effect, Hill slope, minimal effect, and maximal effect (see evalHillModel()). The first of these two are always fit, so model must contain at least 1 and 2. The presence of 3 or 4 will determine if those parameters are also fit, or fixed at the given starting value. So c(1,2,4) will fit the dose of median effect, the Hill slope, and the maximal effect, but will leave the minimal effect fixed at the starting value.

weights

A vector of weights (between 0 and 1) the same length as conc and act which determines the weight with which each measurement will impact the the sum of squared errors. Weights will be multiplied by errors before squaring. If NULL (the default) all weights will be set to 1. Can be a numeric vector, or the name of a column in data if formula is a symbolic formula

start

A vector of four starting values for the Hill model to be fit. Any values not being fit will be fixed at these starting values. If left as NULL, a starting vector will be estimated from the data, but it will almost always be better to provide an explicit staring model.

direction

Determines the possible directionality of the dose response model. If 0 (the default) no additional constraints are placed on the parameters. If greater than 0, the fitting will require that the maximal effect is greater than the minimal effect. If less than 0, the fitting wll require tha the maximal effect is less than the minimal effect.

lower

A vector of lower bounds on the Hill parameter values. Can be the same length as model (in which case the bounds will be applied to the corresponding fit parameters) or the full length of 4. Any parameters for which you do not wish to specify a bound can be set to NA.

upper

A vector of upper bounds on the Hill parameter values. Works the same as parameter lower.

Value

An object of class hillrm, containing the following values:

  • conc: the given vector of concentraitons

  • act: the given vector of responses

  • weights: the vector of measurement weights used in minimizing the sum of squared errors

  • coefficients: the full four-parameter Hill parameter vector (accessible by the function coef())

  • par: the vector of paramters that were actually fit

  • fitted.values: the predicted responses of the best fit model (accessible by the functoin fitted())

  • residuals: the difference between the actual responses and the predicted responses (accessible by the function residuals())

  • model: the vector of values between 1 and 4 specifying the precise model that was fit

  • mname: a character string naming the precise model that was fit. One of "m2p", "m3plc", "m3puc", or "m4p"

  • start: a four-value parameter vector used as the starting value for the model fit

  • direction: the direction constraint used in the fit

  • pbounds: a two-by-four matrix of values specifying the lower and upper bounds used in the fit

Examples

conc <- c(0,2^(-6:3),Inf)
hpar <- c(1,3,0,75)
response <- evalHillModel(conc, hpar) + rnorm(length(conc),sd=7.5)
data <- data.frame(conc=conc,response=response,weight=c(0.5,rep(1,10),0.1))

hfit <- fitHillModel(conc,response,c(1,2,3,4),start=c(0.5,1,0,100))
hfit2 <- fitHillModel(response~conc,data,c(1,2,4),weight,start=c(0.5,1,0,100),
                      direction=0,lower=c(NA,NA,0,0))

basicdrm documentation built on June 22, 2024, 12:22 p.m.