2

Below is some of the summary data from a mixed model I have run in R (produced by summary()):

Fixed effects:
                    Estimate Std. Error         df t value Pr(>|t|)    
(Intercept)       -3.295e-01  1.227e-01  3.740e+01  -2.683   0.0108 *  
STANDING.L         8.447e-02  7.091e-02  7.346e+02   1.188   0.2354    
STANDING.Q        -4.624e-03  5.940e-02  7.323e+02  -0.078   0.9380    
STANDING.C         2.899e-03  5.560e-02  7.327e+02   0.052   0.9585    
FIRST.CLASS1       2.643e-02  7.017e-02  7.308e+02   0.376   0.7068    
CAREER.L           1.300e-01  5.917e-02  7.345e+02   2.189   0.0289 *  
CAREER.Q           8.914e-04  7.370e-02  7.295e+02   0.012   0.9904    
GENDER1            9.411e-02  5.892e-02  7.296e+02   1.596   0.1109    
HS.COURSES.L      -3.996e-02  7.819e-02  7.347e+02  -0.510   0.6102    
HS.COURSES.Q       4.977e-02  6.674e-02  7.322e+02   0.745   0.4567    
HS.COURSES.C       2.087e-02  5.735e-02  7.298e+02   0.364   0.7163    
PARENT.LIVE1       5.770e-03  8.434e-02  7.296e+02   0.068   0.9455    
CHILD.SETTING.L    1.241e-01  6.027e-02  7.288e+02   2.057   0.0400 *  
CHILD.SETTING.Q   -4.911e-02  4.879e-02  7.268e+02  -1.006   0.3146    
ES.EXTRA.L         2.702e-02  8.202e-02  7.287e+02   0.329   0.7421    
ES.EXTRA.Q         1.267e-01  7.761e-02  7.274e+02   1.631   0.1032    
ES.EXTRA.C         8.317e-02  7.533e-02  7.287e+02   1.104   0.2701    
TEACH.TAUGHT1      2.475e-01  6.316e-02  7.268e+02   3.918 9.79e-05 ***
SOME1ELSE.TAUGHT1 -1.818e-03  6.116e-02  7.277e+02  -0.030   0.9763

Several of my predictor variables are ordinal, as indicated by the Linear (.L), Quadratic (.Q), and sometimes Cubic (.C) terms that are being automatically generated for them. My question is this: How could I re-run this same regression removing, say, the ES.EXTRA.C term? In other words, I want to suppress one or more of the automatically-generated polynomial contrasts but potentially keep others. I would have thought update() could do this, but I haven't been able to get it to work.

I can't share my actual data, but this code will create a few outcomes that are sort of similar and include an illustration of smci's answer below as well:

set.seed(151) #Lock in a fixed random structure to these data.
Y.data = sort(round(rnorm(100, 75, 10))) #Some random Y data that are basically the same form as mine.
X.data1 = as.ordered(rep(c(1,2,3,4), each=25)) #Some random X data that are similar in form to mine.

summary(lm(Y.data~X.data1)) #This is what I had been doing, albeit using lmer() instead of lm(). It looks to have been creating the polynomial terms automatically.
summary(lm(Y.data~poly(X.data1, 3))) #Returns an error because X.data1 is not numeric
summary(lm(Y.data~poly(as.numeric(X.data1), 3))) #Now returns a call very similar to the first one, but this time I am in control of which polynomial terms are included.
summary(lm(Y.data~poly(as.numeric(X.data1), 2))) #The cubic term is suppressed now, as desired.

As a follow-up, is there a way using poly() to get only a certain mixture of polynomial terms? Say, the cubic and fourth power ones only? I have no idea why one would want to do that, but it seems like something worth knowing...

Bajcz
  • 433
  • 5
  • 20
  • This is off topic. You may want to try another Stack Exchange site. – Michael R. Chernick Mar 24 '17 at 21:56
  • Hey @MichaelChernick, thanks for the comment. Can you help me migrate this to a more appropriate site, like StackOverflow perhaps? I don't know how to do it myself... – Bajcz Mar 24 '17 at 22:34
  • 1
    You need to post your code. Not a huge dump, just the minimum to reproduce this. In particular we need to see the regression call with the formula. – smci Mar 26 '17 at 15:48
  • Useful reference: [UCLA: "R LIBRARY CONTRAST CODING SYSTEMS FOR CATEGORICAL VARIABLES"](http://stats.idre.ucla.edu/r/library/r-library-contrast-coding-systems-for-categorical-variables/). Look at the section about `contr.poly()` – smci Mar 26 '17 at 16:23
  • Hey @smci, sorry, this just got migrated today and I missed that. I am adding a minimal workable example to highlight your points (I can't share my actual data but I can share something faked to look like part of it). – Bajcz Mar 27 '17 at 16:30
  • `lmer()` is for Fixed-Effects Models, if you don't know what that is, don't use it, use plain `lm()` – smci Mar 27 '17 at 18:27

1 Answers1

1

UPDATE: after you posted your code:

As I guessed you're building a model using polynomials of ordinal variables:

fit <- lm(y ~ poly(STANDING,3) + FIRST.CLASS + poly(CAREER,2) + GENDER +
              poly(HS.COURSES,3) + poly(CHILD.SETTING,2) + poly(ES.EXTRA,3) ...)

If you want to prevent cubic terms, use poly(..., 2) If you really want to only have cubic and quartic terms, no quadratic or linear, a hack is to use I(STANDING^3) + I(STANDING^4), although those will be raw polynomials (not orthogonal, centered and scaled like poly() does). I have never seen a need for this, sounds like a very strange request.

See related:

FOOTNOTE: lmer() is for Fixed-Effects Models, if you don't know what that is, don't use it, use plain lm().

Community
  • 1
  • 1
smci
  • 32,567
  • 20
  • 113
  • 146
  • Hello smci, thanks for the answer! See the code I have added to my question--adjust as you see fit to make maximally useful for others. Also, if you have any info to provide about my follow-up question, I would be interested. Also, thanks for the sources. I will take a look (although at least a few of them seem over my head at first glance). – Bajcz Mar 27 '17 at 16:37
  • Hello smci. Yes, I am a mixed-modeler, so I know the distinction between lm() and lmer() quite well. I just realized, as I was writing code for this, that they behaved the same way, so it was irrelevant which I used to demonstrate. – Bajcz Mar 27 '17 at 23:09