2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Rを使用したGLMM(binomial)の結果を論文に書いたり、Word やパワーポイントに移すのが少し楽になるコード

Last updated at Posted at 2023-11-16

以下のコードを入力すると、表にそのままコピペできる形になります。
output に、本文中で使える (Estimate = ., SE = ., = . , z = ., p < .) の形に出力してくれます。
outputTable に、エクセルでデータ分割をすればそのまま貼り付けられるようにできるデータが入っています。

# GLMMを実行し、summaryの結果を表示する
summary_result <- summary(作成したモデルの名前)

# 固定効果の抽出
fixed_effects <- round(summary_result$coefficients[,"Estimate"], 3)
se <- round(summary_result$coefficients[,"Std. Error"], 3)
z_values <- round(summary_result$coefficients[,"z value"], 3)
p_values <- summary_result$coefficients[,"Pr(>|z|)"]

#p値の整形
p_values_text <- ifelse(p_values < 0.001, "p < .001", paste("p =", gsub("^0", "", formatC(p_values, format = "f", digits = 3))))

#整形した結果の出力
output <- matrix(paste("Estimate =", fixed_effects, ", SE =", se, ", z value =", z_values, ",", p_values_text, sep = " "), ncol = 1)
outputTable <- matrix(paste(fixed_effects, se, z_values, p_values_text, sep = ","), ncol = 1)
colnames(output) <- "Fixed Effects"
print(output) 
print(outputTable) 
2
0
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?