数据集:
random factor:verb_lemma
自变量:number,animacy,order,tense,resultativity,boundedness
因变量:object_case (partitive 0,nominative 1)
代码如下:
m2 = glmer(object_case ~ number + animacy + order + tense + resultativity + boundedness + (1|verb_lemma),
data = lra, family=binomial(link = "logit"),
control=glmerControl(optimizer = "bobyqa"))
summary(m2)
summary 结果如下
Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) [glmerMod
]
Family: binomial ( logit )
Formula: object_case ~ number + animacy + order + tense + resultativity +
boundedness + (1 | verb_lemma)
Data: lra
Control: glmerControl(optimizer = "bobyqa")
AIC BIC logLik deviance df.resid
139.1 173.7 -60.5 121.1 336
Scaled residuals:
Min 1Q Median 3Q Max
-0.5317 0.0000 0.0000 0.0007 0.5398
Random effects:
Groups Name Variance Std.Dev.
verb_lemma (Intercept) 1912 43.73
Number of obs: 345, groups: verb_lemma, 171
Fixed effects:
Estimate Std. Error z value Pr(>|z|)
(Intercept) -45.5773 10.3034 -4.424 9.71e-06 ***
numbersingular 2.4965 2.2802 1.095 0.274
animacyeluta -2.7037 4.8314 -0.560 0.576
animacyinimene -6.2863 5.8948 -1.066 0.286
orderVO -0.8728 2.2550 -0.387 0.699
tensepresent -0.0722 2.5892 -0.028 0.978
resultativityyes 37.1170 7.2732 5.103 3.34e-07 ***
boundednessyes 24.1356 4.3747 5.517 3.45e-08 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Correlation of Fixed Effects:
(Intr) nmbrsn anmcyl anmcyn ordrVO tnsprs rslttv
numbersnglr -0.260
animacyelut -0.443 -0.384
animacyinmn -0.254 -0.292 0.846
orderVO -0.139 -0.106 0.187 0.178
tensepresnt -0.477 0.075 0.442 0.423 0.146
reslttvtyys -0.885 0.329 0.082 -0.106 -0.126 0.271
bounddnssys -0.537 0.370 -0.295 -0.544 -0.023 -0.062 0.680
请问如何将这个output转化为word,以及如何分别将fixed effects,correltaion of fixed effects的output转化为word,请提供代码,谢谢!
没明白你的意思啊,是保存吗
将glmer的结果转为word可以使用R中的flextable
包,可以将glmer的summary中的内容转化为表格形式,然后使用flextable
包将表格输出为word。
首先,需要安装flextable
包:
install.packages("flextable")
然后,将summary(m2)
的内容转化为表格:
library(flextable)
table1 <- flextable(summary(m2)$coefficients)
接下来可以对表格进行一些格式调整,例如:
table1 <- table1 %>%
set_header_labels("Estimate" = "Coefficients", "Pr(>|z|)" = "P-value") %>%
set_caption("Generalized linear mixed model of object_case") %>%
bold(part = "header") %>%
autofit()
最后,将表格输出为word:
library(officer)
doc <- read_docx() %>%
body_add_flextable(table1) %>%
print(target = "example.docx")
以上代码可以将表格输出为名为example.docx
的word文档。
对于分别将fixed effects和correlation of fixed effects的output转化为word,可以使用类似的方法,只需要将需要转化的内容转化为表格,然后进行格式调整和输出即可。
引用chatGPT作答,您可以使用R中的texreg包来将glmer的输出转换为LaTeX表格,然后将其复制并粘贴到Microsoft Word中。以下是将glmer结果转换为LaTeX表格的示例代码:
首先,您需要在R中安装和加载texreg包:
install.packages("texreg")
library(texreg)
然后,您可以使用以下命令将glmer模型转换为LaTeX表格:
texreg(m2, booktabs = TRUE, dcolumn = TRUE, use.packages = FALSE,
caption = "My GLMER Model", label = "tab:glmer")
这将生成一个LaTeX表格,其中包括模型系数、标准误、z值、P值和置信区间。您可以复制并粘贴这个表格到Word中。
如果您只想将模型系数和标准误转换为LaTeX表格,则可以使用以下命令:
texreg(m2, include.ci = FALSE, include.aic = FALSE, booktabs = TRUE, dcolumn = TRUE,
use.packages = FALSE, caption = "My GLMER Model", label = "tab:glmer")
如果您想将相关系数转换为LaTeX表格,则可以使用以下命令:
texreg(m2, include.ci = FALSE, include.aic = FALSE, include.loglik = FALSE,
include.deviance = FALSE, include.nobs = FALSE, custom.coef.names = names(fixef(m2)),
custom.model.names = c("Fixed Effects Correlations"),
custom.lines.before = "\\addlinespace",
custom.note = "Note: Correlation values are shown below diagonal, and standard errors are shown above diagonal.",
booktabs = TRUE, dcolumn = TRUE, use.packages = FALSE,
caption = "My GLMER Model", label = "tab:glmer_corr")
这将生成一个LaTeX表格,其中包括相关系数、标准误和模型名称。在表格下方,您可以看到一个自定义注释,其中说明了如何解释表格中的相关系数。
请注意,您需要将这些命令放在一个R脚本中,并将其保存为一个纯文本文件。在Word中打开此文件,您将看到代码和输出。您可以复制并粘贴LaTeX表格,或使用R Markdown或其他文档生成工具来创建漂亮的文档。
c html导出成word,html转word-html如何转换成WORD
可以借鉴下
https://blog.csdn.net/weixin_42596214/article/details/118284318