I want to make one function where I can easily run multiple models. only the models input variables that are used differ. I use the rpart function for this model. ideally I have a table (named variables) with models and its variables. something that looks like this
model1 model2 model3 …………………
gender gender age
age education wageparents
education nfriends
married
and than have a function where I can just insert fun(data, variables)
what I used so far is:
tree <-rpart(wage ~ gender + age + education, method='class', data=Data, control=rpart.control(minsplit=1, minbucket=1, cp=0.002))
this works, but I have to change the model formula everytime
I tried something like this, but I am not sure what datatype I have to use etc.
wagefun <- function(Data, variables$model1){
tree <-rpart(wage ~ variables$model1, method='class', data=Data, control=rpart.control(minsplit=1, minbucket=1, cp=0.002))
return(tree)
}