Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8206331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:37:42+00:00 2026-06-07T08:37:42+00:00

The problem: I cannot remove a lower order parameter (e.g., a main effects parameter)

  • 0

The problem: I cannot remove a lower order parameter (e.g., a main effects parameter) in a model as long as the higher order parameters (i.e., interactions) remain in the model. Even when doing so, the model is refactored and the new model is not nested in the higher model.
See the following example (as I am coming from ANOVAs I use contr.sum):

d <- data.frame(A = rep(c("a1", "a2"), each = 50), B = c("b1", "b2"), value = rnorm(100))
options(contrasts=c('contr.sum','contr.poly'))
m1 <- lm(value ~ A * B, data = d)
m1

## Call:
## lm(formula = value ~ A * B, data = d)
## 
## Coefficients:
## (Intercept)           A1           B1        A1:B1  
##   -0.005645    -0.160379    -0.163848     0.035523  

m2 <- update(m1, .~. - A)
m2

## Call:
## lm(formula = value ~ B + A:B, data = d)

## Coefficients:
## (Intercept)           B1       Bb1:A1       Bb2:A1  
##   -0.005645    -0.163848    -0.124855    -0.195902  

As can be seen, although I remove one parameter (A), the new model (m2) is refactored and is not nested in the bigger model (m1). If I transform my factors per hand in numerical contrast variables I can get the desired results, but how do I get it using R’s factor capabilities?

The Question: How can I remove a lower order factor in R and obtain a model that really misses this parameter and is not refactored (i.e., the number of parameters in the smaller model must be lower)?


But why? I want to obtain ‘Type 3’ like p-values for a lmer model using the KRmodcomp function from the pbkrtest package. So this example is really just an example.

Why not CrossValidated? I have the feeling that this is really more of an R then a stats question (i.e., I know that you should never fit a model with interactions but without one of the main effects, but I still want to do it).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T08:37:44+00:00Added an answer on June 7, 2026 at 8:37 am

    Here’s a sort of answer; there is no way that I know of to formulate this model directly by the formula …

    Construct data as above:

    d <- data.frame(A = rep(c("a1", "a2"), each = 50),
                    B = c("b1", "b2"), value = rnorm(100))
    options(contrasts=c('contr.sum','contr.poly'))
    

    Confirm original finding that just subtracting the factor from the formula doesn’t work:

    m1 <- lm(value ~ A * B, data = d)
    coef(m1)
    ## (Intercept)          A1          B1       A1:B1 
    ## -0.23766309  0.04651298 -0.13019317 -0.06421580 
    
    m2 <- update(m1, .~. - A)
    coef(m2)
    ## (Intercept)          B1      Bb1:A1      Bb2:A1 
    ## -0.23766309 -0.13019317 -0.01770282  0.11072877 
    

    Formulate the new model matrix:

    X0 <- model.matrix(m1)
    ## drop Intercept column *and* A from model matrix
    X1 <- X0[,!colnames(X0) %in% "A1"]
    

    lm.fit allows direct specification of the model matrix:

    m3 <- lm.fit(x=X1,y=d$value)
    coef(m3)
    ## (Intercept)          B1       A1:B1 
    ## -0.2376631  -0.1301932  -0.0642158 
    

    This method only works for a few special cases that allow the model matrix to be specified explicitly (e.g. lm.fit, glm.fit).

    More generally:

    ## need to drop intercept column (or use -1 in the formula)
    X1 <- X1[,!colnames(X1) %in% "(Intercept)"]
    ## : will confuse things -- substitute something inert
    colnames(X1) <- gsub(":","_int_",colnames(X1))
    newf <- reformulate(colnames(X1),response="value")
    m4 <- lm(newf,data=data.frame(value=d$value,X1))
    coef(m4)
    ## (Intercept)          B1   A1_int_B1 
    ##  -0.2376631  -0.1301932  -0.0642158 
    

    This approach has the disadvantage that it won’t recognize multiple input variables as stemming from the same predictor (i.e., multiple factor levels from a more-than-2-level factor).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This CSS problem is killing me :-( I cannot remove padding under a link
I cannot seem to remove the indent from my unordered list when long lines
How can I solve this problem Cannot Create Forms. No MDI forms are currently
It is known that the halting problem cannot have a definite solution, one that
I came across a problem I cannot solve on my own concerning the downloadable
I have a very simple problem but cannot find a nice solution. I have
I know this has probably been asked before but for my problem I cannot
[Updated, sorry about the change but now to the real problem] I cannot include
I am facing the problem that I cannot properly map my foreign key table
I have a simple problem that i cannot solve. I have a dictionary: aa

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.