Skip to main content
Asher Bill
You do not have to go fast, you just have to keep going
Asked a question 5 months ago

how to use lm function in r?

Where am I?

In answerQA you can ask and answer questions and share your experience with others!

Jaxon Axel
"Knowing other is Intelligence. Knowing yourself is wisdom. Mastering other is strength. Mastering our self is absolute power."

For that you first have to pass the data to the function :



model <- function(data, x){

  lmer(paste("cyl ~", x, "+", "(1|disp)"), data = data)


and then try to call it like the following :

mtcars %>% model('hp')

#Linear mixed model fit by REML ['lmerMod']

#Formula: cyl ~ hp + (1 | disp)

#   Data: data

#REML criterion at convergence: 96.2

#Random effects:

# Groups   Name        Std.Dev3.

# disp     (Intercept) 0.927   

# Residual             0.441   

#Number of obs: 32, groups:  disp, 27

#Fixed Effects:

#(Intercept)           hp  

#     3.1866       0.0196