hi below is my code. I am wondering is there a way to shorten it to be more efficient? create_model_function is a function I created. my concern here is just this is too messy and too long and maybe can become more generalizable. thank u so much!
# happiness as outcome for models. use regular and log rate
dragon_model_happiness <- c(create_model_function(dragons_only, "happiness_rate"),
create_model_function(dragons_only, "log_happiness_rate"))
all_animals_models_happiness <- c(create_model_function(all_animals,"happiness_rate"),
create_model_function(all_animals,"log_happiness_rate"))
# agility as outcome for models. use regular and log rate
dragon_model_agility <- c(create_model_function(dragons_only, "agility_rate"),
create_model_function(dragons_only, "log_agility_rate"))
all_animals_models_agility <- c(create_model_function(all_animals, "agility_rate"),
create_model_function(all_animals, "log_agility_rate"))
In outline, long variable names are useful only when dealing with a multitude of objects. In a short script with a handful, use short names with explanatory comments. Refactor the equation to derive the log version within the function, rather than the data frame. This cuts down on the number of parameters required in the function.
This is only a sketch, not tested.
# shorten names
# data frames
dragons
others
cms <- function(x) do_something(x)
# if the log_variable in the data frame is
# just the log of the variable, do it in
# the function: cms(x) where cms() will
# run a model on x and log(x)
happy <- "happy"
agililty <- "agility"
# these return a list with the two models
# not checked, for lack of data
dmh <- mapply(happy,cms)
dma <- mapply(agility,cms)
amh <- mapply(happy,cms)
ama <- mapply(agility,cms)