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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:33:29+00:00 2026-06-16T00:33:29+00:00

The qqmath function makes great caterpillar plots of random effects using the output from

  • 0

The qqmath function makes great caterpillar plots of random effects using the output from the lmer package. That is, qqmath is great at plotting the intercepts from a hierarchical model with their errors around the point estimate. An example of the lmer and qqmath functions are below using the built-in data in the lme4 package called Dyestuff. The code will produce the hierarchical model and a nice plot using the ggmath function.

library("lme4")
data(package = "lme4")

# Dyestuff 
# a balanced one-way classiï¬cation of Yield 
# from samples produced from six Batches

summary(Dyestuff)             

# Batch is an example of a random effect
# Fit 1-way random effects linear model
fit1 <- lmer(Yield ~ 1 + (1|Batch), Dyestuff) 
summary(fit1)
coef(fit1) #intercept for each level in Batch 

# qqplot of the random effects with their variances
qqmath(ranef(fit1, postVar = TRUE), strip = FALSE)$Batch

The last line of code produces a really nice plot of each intercept with the error around each estimate. But formatting the qqmath function seems to be very difficult, and I’ve been struggling to format the plot. I’ve come up with a few questions that I cannot answer, and that I think others could also benefit from if they are using the lmer/qqmath combination:

  1. Is there a way to take the qqmath function above and add a few
    options, such as, making certain points empty vs. filled-in, or
    different colors for different points? For example, can you make the points for A,B, and C of the Batch variable filled, but then the rest of the points empty?
  2. Is it possible to add axis labels for each point (maybe along the
    top or right y axis, for example)?
  3. My data has closer to 45 intercepts, so it is possible to add
    spacing between the labels so they do not run into each other?
    MAINLY, I am interested in distinguishing/labeling between points on the
    graph, which seems to be cumbersome/impossible in the ggmath function.

So far, adding any additional option in the qqmath function produce errors where I would not get errors if it was a standard plot, so I’m at a loss.

Also, if you feel there is a better package/function for plotting intercepts from lmer output, I’d love to hear it! (for example, can you do points 1-3 using dotplot?)

EDIT: I’m also open to an alternative dotplot if it can be reasonably formatted. I just like the look of a ggmath plot, so I’m starting with a question about that.

  • 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-16T00:33:29+00:00Added an answer on June 16, 2026 at 12:33 am

    One possibility is to use library ggplot2 to draw similar graph and then you can adjust appearance of your plot.

    First, ranef object is saved as randoms. Then variances of intercepts are saved in object qq.

    randoms<-ranef(fit1, postVar = TRUE)
    qq <- attr(ranef(fit1, postVar = TRUE)[[1]], "postVar")
    

    Object rand.interc contains just random intercepts with level names.

    rand.interc<-randoms$Batch
    

    All objects put in one data frame. For error intervals sd.interc is calculated as 2 times square root of variance.

    df<-data.frame(Intercepts=randoms$Batch[,1],
                  sd.interc=2*sqrt(qq[,,1:length(qq)]),
                  lev.names=rownames(rand.interc))
    

    If you need that intercepts are ordered in plot according to value then lev.names should be reordered. This line can be skipped if intercepts should be ordered by level names.

    df$lev.names<-factor(df$lev.names,levels=df$lev.names[order(df$Intercepts)])
    

    This code produces plot. Now points will differ by shape according to factor levels.

    library(ggplot2)
    p <- ggplot(df,aes(lev.names,Intercepts,shape=lev.names))
    
    #Added horizontal line at y=0, error bars to points and points with size two
    p <- p + geom_hline(yintercept=0) +geom_errorbar(aes(ymin=Intercepts-sd.interc, ymax=Intercepts+sd.interc), width=0,color="black") + geom_point(aes(size=2)) 
    
    #Removed legends and with scale_shape_manual point shapes set to 1 and 16
    p <- p + guides(size=FALSE,shape=FALSE) + scale_shape_manual(values=c(1,1,1,16,16,16))
    
    #Changed appearance of plot (black and white theme) and x and y axis labels
    p <- p + theme_bw() + xlab("Levels") + ylab("")
    
    #Final adjustments of plot
    p <- p + theme(axis.text.x=element_text(size=rel(1.2)),
                   axis.title.x=element_text(size=rel(1.3)),
                   axis.text.y=element_text(size=rel(1.2)),
                   panel.grid.minor=element_blank(),
                   panel.grid.major.x=element_blank())
    
    #To put levels on y axis you just need to use coord_flip()
    p <- p+ coord_flip()
    print(p)
    

    enter image description here

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

Sidebar

Related Questions

Recently I found two mathematical functions in qmath.h named qFastSin and qFastCos . These
I am making some approximation functions for exp, log, and sqrt in C for

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.