I have this function which does a geographically weighted regression, I have my shape-file, x for x variable and y for y variable, the ... is for the control variables. For example I want to call a regression first but with multiple control variables - how would I do that?
GWR.function <- function(shape1, x, y, ...) {
model <- lm(shape1[[x]] ~ shape1[[y]] + shape1[[...]])
return(summary(model))
}
I assume that it requires the use of a list but I am not sure how to do this.
In general
do.call()is how you introduce a list as the arguments to a function. Here I combinedywith...and passed the resultingcharactervector toreformulate. If you want to work with individual elements of...,list(...)will convert it to a "regular" list.You could redefine your function as
function(shape1, x, ...)to simplify the code slightly (thenpredvars <- do.call("c", ...))