zl程序教程

您现在的位置是:首页 >  Java

当前栏目

集统计分析数据可视化与一身的利器,这个R包轻松实现

2023-02-18 16:35:32 时间

❝本节来介绍一款R包「rempsyc」即可用来进行统计分析又可用来进行图表绘制,内容很是丰富,原文文档链接见下方,各位观众老爷可以去参考官方文档了解具体细节。❞

原文文档

❝https://rempsyc.remi-theriault.com/#nice-apa-tables❞

加载R包

install.packages("rempsyc")
library(rempsyc)
library(tidyverse)

t-test分析

t.tests <- nice_t_test(data = mtcars,
            response = c("mpg", "disp", "drat", "wt"),
            group = "am")

绘制表格

nice_table(t.tests)

多组进行分析

nice_contrasts(data = mtcars,
               response = c("mpg", "disp"),
               group = "cyl",
               covariates = "hp") -> contrasts
contrasts
nice_table(contrasts, highlight = .001)

lm模型分析

model1 <- lm(mpg ~ cyl + wt * hp, mtcars)
model2 <- lm(qsec ~ disp + drat * carb, mtcars)
mods <- nice_lm(list(model1, model2))
nice_table(mods, highlight = TRUE)

汇总多个模型

model1 <- lm(mpg ~ gear * wt, mtcars)
model2 <- lm(disp ~ gear * wt, mtcars)
my.models <- list(model1, model2)

simple.slopes <- nice_lm_slopes(my.models, predictor = "gear", moderator = "wt")
nice_table(simple.slopes)

绘制小提琴

nice_violin(data = ToothGrowth,group = "dose",response = "len",
            xlabels = c("Low", "Medium", "High"),
            comp1 = 1,comp2 = 3,
            has.d = TRUE,d.y = 28)

ggsave('niceplot.pdf', width = 7, height = 7, unit = 'in', dpi = 300)

绘制线性回归模型结果

model <- lm(mpg ~ wt * cyl + gear, data = mtcars)

nice_table(nice_assumptions(model))

绘制密度图

nice_normality(data = iris,variable = "Sepal.Length",
group = "Species",grid = FALSE,
shapiro = TRUE,histogram = TRUE)