Giter Site home page Giter Site logo

Comments (13)

markgibson9 avatar markgibson9 commented on September 22, 2024 1

from rempsyc.

rempsyc avatar rempsyc commented on September 22, 2024

Thanks for opening an issue, Mark. Can you try the following code for a starter, and then with your own data see if it works?

library(lme4)
library(report)
library(rempsyc)

model_full <- glmer(cbind(incidence, size - incidence) ~ period + (1 | herd),
             data = cbpp, family = binomial)

model_full |> 
  report_table() |>
  nice_table(highlight = TRUE)

Created on 2023-09-28 with reprex v2.0.2

from rempsyc.

rempsyc avatar rempsyc commented on September 22, 2024

If you want a shorter version of the table, you can instead try the following:

library(lme4)
library(report)
library(rempsyc)

model_full <- glmer(cbind(incidence, size - incidence) ~ period + (1 | herd),
             data = cbpp, family = binomial)

model_full |> 
  report_table() |>
  summary() |>
  nice_table(highlight = TRUE)

Created on 2023-09-28 with reprex v2.0.2

from rempsyc.

markgibson9 avatar markgibson9 commented on September 22, 2024

from rempsyc.

rempsyc avatar rempsyc commented on September 22, 2024

Ok, you can define your model the same way you did earlier,

model_full<-glmer(accuracy` ~ SNR + number_speakers + Proximity + Vowel + Level + (1|participant), 
   data=EN, family = binomial)

So no need to specify incidence, that was just to get a glmer model working. The important bit, once you have defined the model, is what follows (the report_table and nice_table functions).

from rempsyc.

markgibson9 avatar markgibson9 commented on September 22, 2024

from rempsyc.

rempsyc avatar rempsyc commented on September 22, 2024

Great, thanks. You can just cite the JOSS paper in your paper if you want, that would be really helpful to me :)

https://doi.org/10.21105/joss.05466

from rempsyc.

rempsyc avatar rempsyc commented on September 22, 2024

Cool, looking forward! :)

from rempsyc.

rempsyc avatar rempsyc commented on September 22, 2024

Regarding your last email question,

When I save flextable as an object:

flextable::save_as_docx(my_table, path = "C://Users//mgibson//Documents//JPHON_EN_SP//nice_table.docx")

It works fine and the doc appears in the folder, but the term column, title, note on significance are missing. The terms etc. do appear in the viewer. I'm assuming it has something to do with the fact that I didn't customize it. In your tutorial I see you have this:

# Standardize variables to get standardized coefficients
mtcars.std <- lapply(mtcars, scale)
# Create a simple linear model
model <- lm(mpg ~ cyl + wt * hp, mtcars.std)
# Gather summary statistics
stats.table <- as.data.frame(summary(model)$coefficients)
# Get the confidence interval (CI) of the regression coefficient
CI <- confint(model)
# Add a row to join the variables names and CI to the stats
stats.table <- cbind(row.names(stats.table), stats.table, CI)
# Rename the columns appropriately
names(stats.table) <- c("Term", "B", "SE", "t", "p", "CI_lower", "CI_upper")

For the mtcars data, but that won't work for my data frame (I assume because my response variable is binary?)

The code I provided earlier simply printed the table to the Viewer, it did not create an object called my_table, but the way it appears in the viewer is exactly how it should appear in the Word document. It does not have to do with the fact that you did not customize the table.

Rather, to know the expected output, we should look at the example I shared earlier.

  1. First of all, from the picture I shared, we can see that there is no "Term" column, because it is called "Parameter". Is that ok for you? Otherwise you can either rename by hand in the Microsoft Word output, or in the data frame before passing it to nice_table().

  2. For the title, and note on significance, you have to provide those directly to the nice_table() function, like in the tutorial, using the title and note arguments.

Thus, In order to save the table to Word with the title and note, you will have to use adjusted code where you define my_table, e.g., like this:

library(lme4)
library(report)
library(rempsyc)

model_full <- glmer(cbind(incidence, size - incidence) ~ period + (1 | herd),
                    data = cbpp, family = binomial)

my_table <- model_full |> 
  report_table() |>
  summary() |>
  nice_table(highlight = TRUE,
             title = c("Table 1", "GLMER regression model"),
             note = c(
               "This is an example note about the data.",
               "* p < .05, ** p < .01, *** p < .001"
               ))

flextable::save_as_docx(my_table, path = "nice_table.docx")

Created on 2023-09-29 with reprex v2.0.2

Does that help?

from rempsyc.

markgibson9 avatar markgibson9 commented on September 22, 2024

When I save flextable as an object:

flextable::save_as_docx(my_table, path = "C://Users//mgibson//Documents//JPHON_EN_SP//nice_table.docx")

It works fine and the doc appears in the folder, but the term column, title, note on significance are missing. The terms etc. do appear in the viewer. I'm assuming it has something to do with the fact that I didn't customize it. In your tutorial I see you have this:

# Standardize variables to get standardized coefficients
mtcars.std <- lapply(mtcars, scale)
# Create a simple linear model
model <- lm(mpg ~ cyl + wt * hp, mtcars.std)
# Gather summary statistics
stats.table <- as.data.frame(summary(model)$coefficients)
# Get the confidence interval (CI) of the regression coefficient
CI <- confint(model)
# Add a row to join the variables names and CI to the stats
stats.table <- cbind(row.names(stats.table), stats.table, CI)
# Rename the columns appropriately
names(stats.table) <- c("Term", "B", "SE", "t", "p", "CI_lower", "CI_upper")

from rempsyc.

markgibson9 avatar markgibson9 commented on September 22, 2024

When I run the code, the table I get in the viewer is perfect:

image.png

With significant codes at the bottom (,,).

But when I write it to a Word doc, I get this:

image.png

With no title, notes, Parameter reads row.names(stats.table) and the p-value column omits significance codes and eliminates the final 1 of <0.001. I know I have to be doing something stupid, but here is the code I'm inserting:

model_full<-glmer(accuracy ~ SNR + number_speakers + Proximity + Vowel + Level + (1|participant), data=df, family = binomial)

my_table <- model_full |>
report_table() |>
summary() |>
nice_table(highlight = TRUE,
title = c("Table 1", "Output of GLMER regression model"),
note = c(
"Significance levels.",
"* p < .05, ** p < .01, *** p < .001"
))

my_table <- nice_table(stats.table)

flextable::save_as_docx(my_table, path = "C://Users//mgibson//Documents//JPHON_EN_SP//nice_table.docx")

from rempsyc.

rempsyc avatar rempsyc commented on September 22, 2024

Ok, please try the steps below:

  1. Try to type packageVersion("flextable") and post the answer here.
  2. Next, install the latest flextable version by typing install.packages("flextable")
  3. Restart your R session and then try your steps again to save the Word document and report on the result.

from rempsyc.

markgibson9 avatar markgibson9 commented on September 22, 2024

from rempsyc.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.