Comments (13)
from rempsyc.
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.
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.
from rempsyc.
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.
from rempsyc.
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.
Cool, looking forward! :)
from rempsyc.
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.
-
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()
. -
For the title, and note on significance, you have to provide those directly to the
nice_table()
function, like in the tutorial, using thetitle
andnote
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.
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.
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.
Ok, please try the steps below:
- Try to type
packageVersion("flextable")
and post the answer here. - Next, install the latest
flextable
version by typinginstall.packages("flextable")
- Restart your R session and then try your steps again to save the Word document and report on the result.
from rempsyc.
from rempsyc.
Related Issues (17)
- Unable to install HOT 3
- test requires suggtested package HOT 5
- Package install issue HOT 4
- Comments on JOSS submission HOT 5
- Review for JOSS Submission HOT 2
- Nice_table: replacing rounding with scientific notation HOT 2
- nice_t_test for specific mean? HOT 7
- How to make correlation tables with stars for significance? HOT 4
- Emmeans for nice_table? HOT 5
- standardized slopes in nice_table() HOT 1
- Nice_table: Significance Asterisks for p value HOT 1
- Logistic regression HOT 3
- Feature request: Add support for `separate.header = TRUE` used along with automatic header symbol formatting HOT 6
- Center and merge duplicated cells in `nice_table`
- change row names HOT 2
- Generation of a sample demographics table HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rempsyc.