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 8858991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:57:04+00:00 2026-06-14T14:57:04+00:00

I have a mer object created with a called to lmer() . I can

  • 0

I have a mer object created with a called to lmer().

I can obtain the random effects with ranef() but I would also like to have corresponding number of observations for each random effect – is there an easy way to do that ?

Additional Info:

I may not have made myself quite clear above. For example, if I have a simple 2-level model with patients clustered within hospitals and random intercepts for hospitals, I would like to extract the random effects for each hospital with ranef() together with the number of patients within each hospital. At the moment, I use

ranef(fullmodel)[[1]]

which gives me something like:

     (Intercept)
ADE -0.108195883
BEJ -0.005761677
CIS  0.124129426
CMH  0.270879048
CSI  0.285344837
CUL  0.189308979

I would like to get something like:

     (Intercept)  n
ADE -0.108195883  77
BEJ -0.005761677  171
CIS  0.124129426  201
CMH  0.270879048  39
CSI  0.285344837  171
CUL  0.189308979  131

To do this, I have been using

fullmodel <- glmer(.....+(1|hospital), data=dt1)

freqs <- as.data.frame(table(dt1$hospital))
freqs <- freqs[foo$Freq>0,]

And then cbinding this to the results from ranef(fullmodel)[[1]]

However this seems unsophisticated and prone to error.

  • 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-14T14:57:06+00:00Added an answer on June 14, 2026 at 2:57 pm

    ranef returns a list of matrices corresponding to grouping factors, where the rows in each matrix correspond to observations (factor levels) for a random effect and the columns correspond to random effect variables (intercept, slope etc.). Thus the easiest way to get the numbers of observations is

    sapply(ranef(model),nrow)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have a look at the menu link Produkter on http://marckmann.se/ I would like to
Have a recurring situation, petty I know, but I'd like to consolidate the following:
Have an app that can use tts to read text messages. It can also
Have read a lot of articles, but can't make animate function to run indefinitely.
have written this little class, which generates a UUID every time an object of
Have a procedure which looks like Procedure TestProc(TVar1, TVar2 : variant); Begin TVar1 :=
Have a simple contact us XPage created. Have server side validation in place that
have some headers like: HTTP/1.1 100 Continue HTTP/1.1 302 Found HTTP/1.1 200 OK HTTP/1.1
Have a photography site that I want to prevent image copying from. How can
Have created a ATL COM project through which I am inserting Menu Items to

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.