Cross Validated
2026-08-07 21:10 UTC
By BL14
AI-113-20260807-social-media-afe67dea
What is the "r_matrix" required in statsmodels to perform f-test for linear mixed effects model?
I am new to statistical coding and am using the statsmodels library for now, because I already have a basis in python. I have fit a linear mixed model like so: SMMixedModel= smf.mixedlm("Response ~ Predictor + Sex + Age + Height", SubjectData, groups=SubjectData["Subject"]) SMMixedModelfit_RESPONSE = SMMixedModel.fit() This is a continuous response variable and one predictor of interest, plus covariates. There are 10 subjects with 5 observations each, so there is a random subject-level intercept. The model is converging fine and I'm reasonably confident this is a good way to model the relationship I am interested in. The output of SMMixedModelfit_RESPONSE.summary() includes a z-score and associated p-value. I have two questions: A paper whose results I am trying to replicate reports the f-statistic and its p-value, whereas the statsmodel output only includes the z-statistic. Under what circumstances is the f-statistic preferable? From what I can figure out, to get the results of an f-test on my model, I should used .f_test(), which takes as an argument a "r_matrix", which, it says can be any of the following: array : An r x k array where r is the number of restrictions to test and k is the number of regressors. It is assumed that the linear combination is equal to zero. str : The full hypotheses to test can be given as a string. See the examples. tuple : A tuple of arrays in the form (R, q), q can be either a scalar or a length k row vector. The r_matrix in the example given…
I am new to statistical coding and am using the statsmodels library for now, because I already have a basis in python. I have fit a linear mixed model like so: SMMixedModel= smf.mixedlm("Response ~ Predictor + Sex + Age + Height", SubjectData, groups=SubjectData["Subject"]) SMMixedModelfit_RESPONSE = SMMixedModel.fit() This is a continuous response variable and one predictor of interest, plus covariates. There are 10 subjects with 5 observations each, so there is a random subject-level intercept. The model is converging fine and I'm reasonably confident this is a good way to model the relationship I am interested in. The output of SMMixedModelfit_RESPONSE.summary() includes a z-score and associated p-value. I have two questions: A paper whose results I am trying to replicate reports the f-statistic and its p-value, whereas the statsmodel output only includes the z-statistic. Under what circumstances is the f-statistic preferable? From what I can figure out, to get the results of an f-test on my model, I should used .f_test(), which takes as an argument a "r_matrix", which, it says can be any of the following: array : An r x k array where r is the number of restrictions to test and k is the number of regressors. It is assumed that the linear combination is equal to zero. str : The full hypotheses to test can be given as a string. See the examples. tuple : A tuple of arrays in the form (R, q), q can be either a scalar or a length k row vector. The r_matrix in the example given…
Full article content could not be extracted automatically. Read the original below.
Source:
Cross Validated
· stats.stackexchange.com