mlcollyer / RRPP

RRPP: An R package for fitting linear models to high-dimensional data using residual randomization
https://mlcollyer.github.io/RRPP/
4 stars 1 forks source link

Support to coerce anova.lm.rrpp to a data.frame for integration with knitr #11

Closed drpradeepharish closed 1 year ago

drpradeepharish commented 1 year ago

Is it possible to coerce a lm.rrpp object to a data.frame / other type that is supported by knitr to export the data in a pretty table please?

library(tidyverse)
library(knitr)
library(kableExtra)
library(rrpp)

rrppModelFit <-
  lm.rrpp(
    distanceSummaryData ~ condition, #
    data = rrppSummaryData,
    block = rrppSummaryData$patient_id,
    iter = 10,
    parallel = 12,
    SS.type = "I",
    turbo = FALSE
  )

anova.lm.rrpp(rrppModelFit) %>% knitr() 

outputs

Error in as.data.frame.default(x) : cannot coerce class ‘"anova.lm.rrpp"’ to a data.frame

drpradeepharish commented 1 year ago

Solved as

anova.lm.rrpp(rrppModelFit) %>% .$table %>% kable()

mlcollyer commented 1 year ago

If your goal is to have a data frame for ANOVA output, no coercion is needed. The $table output is already a data.frame object. This should work:

anova(rrppModelFit)$table %>% knitr() A class anova.lm.rrpp object is a list with the following attributes:

$names [1] "table" "perm.method" "perm.number" "est.method" "SS.type" "effect.type" [7] "call”

I think you are expecting the table to be the only output.

Best, Mike

On Sep 18, 2023, at 5:27 PM, raka-everton @.***> wrote:

Is it possible to coerce a lm.rrpp object to a data.frame / other type that is supported by knitr to export the data in a pretty table please?

library(tidyverse) library(knitr) library(kableExtra) library(rrpp)

rrppModelFit <- lm.rrpp( distanceSummaryData ~ condition, # data = rrppSummaryData, block = rrppSummaryData$patient_id, iter = 10, parallel = 12, SS.type = "I", turbo = FALSE )

anova.lm.rrpp(rrppModelFit) %>% knitr() outputs

Error in as.data.frame.default(x) : cannot coerce class ‘"anova.lm.rrpp"’ to a data.frame

— Reply to this email directly, view it on GitHub https://github.com/mlcollyer/RRPP/issues/11, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABUNU4WSRCKTX2LJ46KRNR3X3C4DZANCNFSM6AAAAAA45KTZG4. You are receiving this because you are subscribed to this thread.

drpradeepharish commented 1 year ago

list with the following attributes:

Yep, just realised that after I posted the issue. Hence closed it with utmost speed :P

Sorry for the bother, and thank you for your work on the package. Really appreciate it.

mlcollyer commented 1 year ago

No worries, and you’re welcome!

On Sep 19, 2023, at 4:22 AM, raka-everton @.***> wrote:

list with the following attributes:

Yep, just realised that after I posted the issue. Hence closed it with utmost speed :P

Sorry for the bother, and thank you for your work on the package. Really appreciate it.

— Reply to this email directly, view it on GitHub https://github.com/mlcollyer/RRPP/issues/11#issuecomment-1725044521, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABUNU4QHKXHAX7RNNJUTCN3X3FI3VANCNFSM6AAAAAA45KTZG4. You are receiving this because you commented.