I am attempting to manually translate some R code into Python and encountered this snippet:
"drm" <- function(
formula, curveid, pmodels, weights, data = NULL, subset, fct,
type = c("continuous", "binomial", "Poisson", "quantal", "event"), bcVal = NULL, bcAdd = 0,
start, na.action = na.omit, robust = "mean", logDose = NULL,
control = drmc(), lowerl = NULL, upperl = NULL, separate = FALSE,
pshifts = NULL)
{
## ... elided ...
## Storing call details
callDetail <- match.call()
## Handling the 'formula', 'curveid' and 'data' arguments
anName <- deparse(substitute(curveid)) # storing name for later use
if (length(anName) > 1) {anName <- anName[1]} # to circumvent the behaviour of 'substitute' in do.call("multdrc", ...)
if (nchar(anName) < 1) {anName <- "1"} # in case only one curve is analysed
mf <- match.call(expand.dots = FALSE)
nmf <- names(mf)
mnmf <- match(c("formula", "curveid", "data", "subset", "na.action", "weights"), nmf, 0)
mf[[1]] <- as.name("model.frame")
mf <- eval(mf[c(1,mnmf)], parent.frame()) #, globalenv())
mt <- attr(mf, "terms")
dose <- model.matrix(mt, mf)[,-c(1)] # with no intercept
resp <- model.response(mf, "numeric")
origDose <- dose
origResp <- resp # in case of transformation of the response
lenData <- length(resp)
numObs <- length(resp)
xDim <- ncol(as.matrix(dose))
varNames <- names(mf)[c(2, 1)]
varNames0 <- names(mf)
# only used once, but mf is overwritten later on
## Retrieving weights
wVec <- model.weights(mf)
if (is.null(wVec))
{
wVec <- rep(1, numObs)
}
## Finding indices for missing values
missingIndices <- attr(mf, "na.action")
if (is.null(missingIndices)) {removeMI <- function(x){x}} else {removeMI <- function(x){x[-missingIndices,]}}
## Handling "curveid" argument
assayNo <- model.extract(mf, "curveid")
if (is.null(assayNo)) # in case not supplied
{
assayNo <- rep(1, numObs)
}
uniqueNames <- unique(assayNo)
colOrder <- order(uniqueNames)
uniqueNames <- as.character(uniqueNames)
# ...
}
What is this doing? I see in the documentation for match.call()
that
match.call
returns a call in which all of the specified arguments are specified by their full names.
But I don't understand what this means. What is "a call" in this context? What does it mean that "arguments are specified by their full names"?
Ultimately, the important part is what is stored in dose
and resp
. These variables are used later so I need an understanding of what their values are so I can do something similar in Python (potentially with numpy, pandas, and scipy).