Many questions (e.g., Centering in linear regression & How to include a linear and quadratic term when also including interaction with those variables? ) have been asked about mean centering (aka demeaning) higher order terms in linear models. Does anyone know how common statistics packages handle mean centering for these higher order (e.g., quadratic) terms?
Here's an example. Let's say our data table (tbl) includes only an outcome variable, y, and a predictor, x, and we would like to run a GLM that includes an intercept, the linear term, and the quadratic term. Sample syntax (for fitglm in MATLAB):
mdl = fitglm(tbl,'purequadratic')
(Here, I've used modelspec to add the quadratic term to the model.)
In this case, would MATLAB (or another statistics package like SPSS) remove the mean by
- mean centering x and then squaring that term or
- squaring x and then mean centering x^2
when modeling the quadratic term?
What is the "more correct" method?
mean
computes a mean, which is implemented in the "underlying code." There are a million other questions that refer to specific software packages on .SX, how is this any different? $\endgroup$edit fitglm
(and then probablyedit GeneralizedLinearModel.fit
) and see the exact code used. (You can even overwrite it and totally mess up your MATLAB installation! :) ) $\endgroup$