Skip to main content
Jose Leo
Accept no one's definition of your life: define yourself.
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!

Robert David
Today I accept that for some people, I may be too much or too little. But for the people who deserve me, I am just right.

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. Dev.

# disp     (Intercept) 0.927   

# Residual             0.441   

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

#Fixed Effects:

#(Intercept)           hp  

#     3.1866       0.0196