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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:54:08+00:00 2026-06-04T11:54:08+00:00

I want to have correlation matrix with p-values for xtable to be use in

  • 0

I want to have correlation matrix with p-values for xtable to be use in Sweave. I tried this

library(ltm)
library(xtable)
mat <- matrix(rnorm(1000), 100, 10, dimnames = list(NULL, LETTERS[1:10]))
rcor.test(mat)
xtable(rcor.test(mat))

and it throws this error:

Error in UseMethod("xtable") : 
  no applicable method for 'xtable' applied to an object of class "rcor.test"

I wonder how to get the correlation matrix with p-values for xtable to be use in Sweave. Thanks in advance for your help.

  • 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-04T11:54:09+00:00Added an answer on June 4, 2026 at 11:54 am

    To see what’s going on I would always suggest saving the object of interest and then looking at its structure using str.

    library(ltm)
    library(xtable)
    mat <- matrix(rnorm(1000), 100, 10, dimnames = list(NULL, LETTERS[1:10]))
    out <- rcor.test(mat)
    str(out)
    

    and it looks like the table that is being printed isn’t actually stored in here. So let’s look at the print method for rcor.test

    getAnywhere(print.rcor.test)
    

    We see that that method actually constructs the matrix that gets printed out but doesn’t return it. So to get the matrix so that we can use xtable from this we’ll just… steal the code to construct that matrix. Instead of printing out the matrix and then returning the original object we’ll return the constructed matrix.

    get.rcor.test.matrix <- function (x, digits = max(3, getOption("digits") - 4), ...) 
    {
        ### Modified from print.rcor.test
        mat <- x$cor.mat
        mat[lower.tri(mat)] <- x$p.values[, 3]
        mat[upper.tri(mat)] <- sprintf("%6.3f", as.numeric(mat[upper.tri(mat)]))
        mat[lower.tri(mat)] <- sprintf("%6.3f", as.numeric(mat[lower.tri(mat)]))
        ind <- mat[lower.tri(mat)] == paste(" 0.", paste(rep(0, digits), 
            collapse = ""), sep = "")
        mat[lower.tri(mat)][ind] <- "<0.001"
        ind <- mat[lower.tri(mat)] == paste(" 1.", paste(rep(0, digits), 
            collapse = ""), sep = "")
        mat[lower.tri(mat)][ind] <- ">0.999"
        diag(mat) <- " *****"
        cat("\n")
    
        ## Now for the modifications
        return(mat)
    
        ## and ignore the rest
        #print(noquote(mat))
        #cat("\nupper diagonal part contains correlation coefficient estimates", 
        #    "\nlower diagonal part contains corresponding p-values\n\n")
        #invisible(x)
    }
    

    Now let’s get our matrix and use xtable on it.

    ourmatrix <- get.rcor.test.matrix(out)
    xtable(ourmatrix)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a matrix with two columns. I want to calculate running 60-day correlation
I have huge matrix with a lot of missing values. I want to get
I have a class and I want to have some bit masks with values
I have a large correlation matrix result in R - for now about 30
i want have an image and i want to set it as a background
want to have a Hyperlink-Button in a gridView in which I can display a
I have want to save a form in Symfony2, based on a form type,
I want to have a java app running, using a function/method (with as little
I want to have the ListItems to extend with their orange background the full
I want to have a similar tool in Emacs as the following in Vim

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.