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

  • SEARCH
  • Home
  • 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 8844769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:34:12+00:00 2026-06-14T11:34:12+00:00

In R, we can use model.matrix() to construct design matrices, for example, grp.ids =

  • 0

In R, we can use model.matrix() to construct design matrices, for example,

grp.ids = as.factor(c(rep(1,8), rep(2,4), rep(3,2)))
x = model.matrix(~grp.ids)

gives the design matrix x:

   (Intercept) grp.ids2 grp.ids3
1            1        0        0
2            1        0        0
3            1        0        0
4            1        0        0
5            1        0        0
6            1        0        0
7            1        0        0
8            1        0        0
9            1        1        0
10           1        1        0
11           1        1        0
12           1        1        0
13           1        0        1
14           1        0        1
attr(,"assign")
[1] 0 1 1
attr(,"contrasts")
attr(,"contrasts")$grp.ids
[1] "contr.treatment"

However, if now I am given a design matrix x as above, and hope to get the “grouping vector” grp.ids by somehow manipulating on x. How can I do that? Thanks!

  • 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-14T11:34:13+00:00Added an answer on June 14, 2026 at 11:34 am

    I don’t believe you could recover grp.id exactly as it was originally created because it’s not possible to tell what the original values of the ids were. You can create a vector that results in the same model.maxtrix though.

    factor(apply(x, 1, paste, collapse = "."), labels = seq(ncol(x)))
    

    However, this gets pretty close in this particular case.


    The labels for the previous one give the order of 1, 3, 2 (instead of the desired 1, 2, 3) and that is because we get “1.0.0”, “1.1.0”, “1.0.1” as our actual output and sorted alphanumerically these give the order 1, 3, 2. If we reversed the input string so we had “0.0.1”, “0.1.1” and “1.0.1” then this would give the desired order so the following should work

    factor(apply(x, 1, function(x){paste(rev(x), collapse = ".")}), labels = seq(ncol(x)))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What's the best way to design/use my model and NSFetchedResultsController so that I can
I have page where I use model which can have different types (depending by
I'd like to use model binding to keep my controllers looking cleaner, you can
in my view Inherits=System.Web.Mvc.ViewUSerControl<Model.Person> How can I use an interface to restrict what the
I have a data set that I use the model.matrix() function on to convert
I know I can use another model inside a controller by doing $this->loadModel(MyModel) ,
When I use Python to model a 3-Dimensional matrix, I first make a multi-array
In org-mode, when you export HTML projects you can use templates to give all
I use emacs-mode. How can I navigate to function definition by name? Emacs has
how can I open a modal window using javascript only. I can't use own

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.