Questions tagged [mlm]

"mlm" (multiple / multivariate linear models; linear models with multiple LHS / responses) is a special class of model object returned by `lm()` function in R for fitting linear regression models. When using this tag, please specify [r] and [lm] tags as well.

"mlm" model class is not widely known by lm() users. For an introductory example, please refer to Fitting a linear model with multiple LHS. Also read Run lm with multiple responses and weights for the limitations of "mlm".


R does not have full support for "mlm" class at the moment. Here is an overview:

  • The following generic functions work and would return a matrix:

    coef(), residuals(), fitted(), vcov()
    
  • The following generic functions work and would return a list:

    summary(), anova()
    
  • The following generic functions have limited support for "mlm":

    predict()
    
  • The following generic functions do not work at all for "mlm":

    rstandard(), plot(), confint()
    

The aim of this wiki page is to direct "mlm" users to efficient solutions of various inference and diagnostic tasks. Here is a good collection:

Model Summary

Model Prediction

Model Diagnostic


Please read above questions carefully, and only ask a new question when it is not answered in above.

69 questions
7
votes
1 answer

Fitting a linear model with multiple LHS

I am new to R and I want to improve the following script with an *apply function (I have read about apply, but I couldn't manage to use it). I want to use lm function on multiple independent variables (which are columns in a data frame). I used for…
bogdan.narcis
  • 151
  • 2
  • 7
6
votes
2 answers

Obtain residual standard errors of an "mlm" object returned by `lm()`

I've used lm() to fit multiple regression models, for multiple (~1 million) response variables in R. Eg. allModels <- lm(t(responseVariablesMatrix ~ modelMatrix) This returns an object of class "mlm", which is like a huge object containing all the…
user2141118
  • 103
  • 1
  • 1
  • 4
4
votes
3 answers

Get confidence intervals for regression coefficients of "mlm" object returned by `lm()`

I'm running a multivariate regression with 2 outcome variables and 5 predictors. I would like to obtain the confidence intervals for all regression coefficients. Usually I use the function lm but it doesn't seem to work for a multivariate regression…
msoftrain
  • 1,017
  • 8
  • 23
4
votes
3 answers

Obtain standard errors of regression coefficients for an "mlm" object returned by `lm()`

I'd like to run 10 regressions against the same regressor, then pull all the standard errors without using a loop. depVars <- as.matrix(data[,1:10]) # multiple dependent variables regressor <- as.matrix([,11]) # independent variable allModels <-…
ch-pub
  • 1,664
  • 6
  • 29
  • 52
4
votes
1 answer

Obtain t-statistic for regression coefficients of an “mlm” object returned by `lm()`

I've used lm() to fit multiple regression models, for multiple (~1 million) response variables in R. Eg. allModels <- lm(t(responseVariablesMatrix) ~ modelMatrix) This returns an object of class "mlm", which is like a huge object containing all the…
user2141118
  • 103
  • 1
  • 1
  • 4
3
votes
0 answers

Fixing random slopes and random intercepts values in lme4

I'm currently trying to calculate the effect size (Cohen's f^2) of a given effect but need to run a null and partial model with the random effects pre-specified in order to do so (according to Selya et al., 2012 for dealing with continuous…
3
votes
1 answer

Prediction of 'mlm' linear model object from `lm()`

I have three datasets: response - matrix of 5(samples) x 10(dependent variables) predictors - matrix of 5(samples) x 2(independent variables) test_set - matrix of 10(samples) x 10(dependent variables defined in response) response <-…
Martin James
  • 151
  • 2
  • 10
2
votes
3 answers

How to find child of any node in PHP MySQL?

I have a MLM Binary tree and I want to find all the parent and child of that user. How can I do that? For example: A B C D E F G Basically, I am not able to create two PHP MySQL functions in which one will…
Shivam
  • 103
  • 7
2
votes
0 answers

MLM Tree - how to Count nodes according level and divide commission by level

I want to divide commission level by level nodes. Fist level completed commission 7% Second level completed commission 14% third level completed commission 21% like this tree image example I try this code but Output = array(4) { [3]=> int(0) …
Aniket kumar
  • 65
  • 1
  • 12
2
votes
0 answers

PHP code to track infinite levels of referrals and count

am currently working on making a php code that would count all users referred directly and indirectly a person. In my mysql database, each user have a column called "upline" which is the referrer. *P.S The referral system is by referral link by the…
Powhattan
  • 41
  • 4
2
votes
1 answer

Multi Level Marketing SQL Query to calculate turnover of the team

I have a users table that looks someting like this : ID NAME 1 Robin 2 Edward 3 Donald 4 Julie The 2nd table user_tree ID USER_ID TREE 1 1 ["2","3","4"] 2 2 ["3","4"] 3 3 ["4"] 4 4 [] The 3rd table orders ID AMOUNT…
2
votes
2 answers

rstudent() returns incorrect result for an "mlm" (linear models fitted with multiple LHS)

I know that the support for linear models with multiple LHS is limited. But when it is possible to run a function on an "mlm" object, I would expect the results to be trusty. When using rstudent, strange results are produced. Is this a bug or is…
2
votes
1 answer

MYSQL spillover function

I am currently trying to code a Networking website and am stuck at the spillover function stage.Here is how it works, each registered user of the site is only allowed to refer two people into the network (they have a referral link for this). If…
Powhattan
  • 41
  • 4
2
votes
1 answer

Applying lm() and predict() to multiple columns in a data frame

I have an example dataset below. train<-data.frame(x1 = c(4,5,6,4,3,5), x2 = c(4,2,4,0,5,4), x3 = c(1,1,1,0,0,1), x4 = c(1,0,1,1,0,0), x5 = c(0,0,0,1,1,1)) Suppose I want to create separate models for column x3, x4, x5 based on…
SRB
  • 35
  • 1
  • 1
  • 6
2
votes
3 answers

Fit many linear models in R with identical design matrices

For a neuroimaging application, I'm trying to fit many linear models by least squares in R (standard call to lm). Imagine I have a design matrix X. This design matrix will be the same across all of the models. The data (Y) that is being fit will…
Daniel Kessler
  • 1,172
  • 17
  • 21
1
2 3 4 5