2
$\begingroup$

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

  1. mean centering x and then squaring that term or
  2. squaring x and then mean centering x^2

when modeling the quadratic term?

What is the "more correct" method?

$\endgroup$
8
  • $\begingroup$ MATLAB is proprietary software. We cannot know what procedures are implemented by the underlying code. At any rate, this question is off-topic here. You may want to rephrase this in a non-software specific way, or it may be closed. $\endgroup$ Jun 2, 2015 at 17:32
  • $\begingroup$ @gung We know that e.g. 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$
    – kyle
    Jun 2, 2015 at 17:43
  • 1
    $\begingroup$ @kyle, there are many questions on CV that are related to various software, but questions that are purely about software & not about statistics are off-topic here & have been for a long time. 'Would 1 or 2 be better for X?' is a statistical question & would be on-topic here; 'Is MATLAB doing 1 or 2?' is a question about MATLAB, not a question about statistics. It is off-topic here. $\endgroup$ Jun 2, 2015 at 17:51
  • 1
    $\begingroup$ @gung fair points, but the question asks about general practices of mean centering (which I would answer but I have no idea), then gives MATLAB as an explicit example. The question could easily be rephrased as "What software package should I use to obtain mean-centering method X?" They're functionally isomorphic, and the restatement is a valid expression of "Would 1 or 2 be better for X?", so the question itself should be okay... $\endgroup$
    – kyle
    Jun 2, 2015 at 17:55
  • 2
    $\begingroup$ @kyle and (@gung probably): MATLAB is "semi-opensource" at times. This is one of those times. Just type edit fitglm(and then probably edit GeneralizedLinearModel.fit) and see the exact code used. (You can even overwrite it and totally mess up your MATLAB installation! :) ) $\endgroup$
    – usεr11852
    Jun 2, 2015 at 18:18

0