I have a likelihood function that comes as an argument to the maxLik
function of the maxLik
package. For instance:
library(maxLik) likFun <- function(param, x, y, h) { dep <- as.matrix(x[,y]) indep <- as.matrix(x[,h]) indep <- as.matrix(cbind(cons=1, indep)) k <- dim(indep)[2] beta <- as.matrix(param[1:k]) xbeta <- crossprod(t(indep), beta) sig <- param[k+1] res <- (dep-xbeta)/sig sum( (-(1/2)*log(2*pi)) - ((1/2)*log((sig)^2)) - ((res^2)/2) ) } model <- maxLik(likFun, start=c(0,0,0,1), grad=NULL, hess=NULL, x=mtcars, y="mpg", h=c("cyl", "hp")) summary(model)
In principle, the aforementioned likelihood function uses the maximum probability for a multiple regression model. My question is: how to create a formula
in R (for a package), for example, in lm
, so that the user can enter a dependent variable and independent variables and data. I checked model.matrix
, but I'm not sure if this is the one I should look for. Any suggestion in this regard would be greatly appreciated.
source share