简体   繁体   English

在 R 中创建多元 QQ 图

[英]Creating multivariate Q-Q Plots in R

I wish to test for multivariate and univariate normality with QQ plots in R. I have used several different methods - they all do not seem to work.我希望用 R 中的 QQ 图测试多元和单变量正态性。我使用了几种不同的方法 - 它们似乎都不起作用。 I am new to R, and would be incredibly grateful for any help.我是 R 的新手,对任何帮助都会非常感激。

My data set = vdata_clean1我的数据集 = vdata_clean1

I have 15 predicting variables (IV's), but no response variable (DV) because I am running a Confirmatory Factor Analysis (the 15 variables represent 15 different types of items that make up the scale I am testing).我有 15 个预测变量 (IV),但没有响应变量 (DV),因为我正在运行验证性因子分析(这 15 个变量代表构成我正在测试的量表的 15 种不同类型的项目)。

I have installed the following packages:我已经安装了以下软件包:

install.packages("lavaan", dependencies=TRUE)
install.packages ("semPlot")
install.packages ("semTools")
install.packages("psych")
install.packages("MVN")
install.packages("mvtnorm")
install.packages("ggplot2")
install.packages("qgraph")
install.packages("psych")
  1. First, I used the mvn function (multivariate qq plot)首先,我使用了 mvn 函数(多元 qq 图)

     mvn(data = vdata_clean1, subset = NULL, mvnTest = c("mardia"), covariance = TRUE, tol = 1e-25, alpha = 0.5, scale = FALSE, desc = TRUE, transform = "none", R = 1000, univariateTest = c("SW"), univariatePlot = "none", multivariatePlot = "qq", multivariateOutlierMethod = "none", bc = FALSE, bcType = "rounded", showOutliers = FALSE, showNewData = FALSE)

    => I receive no error messages but the plots do not show. => 我没有收到错误消息,但没有显示图。

- ——

  1. Second, I tried the qqnorm function (multivariate qq plot)二、尝试了qqnorm函数(多元qq图)

     qqnorm(vdata_clean1, ylim, main = "Normal QQ Plot", xlab = "Theoretical Quantiles", ylab = "Sample Quantiles", plot.it = TRUE, datax = FALSE)

    => I receive the following error message and no plots: => 我收到以下错误消息,但没有图表:

     Error: Must use a vector in `[`, not an object of class matrix. Call `rlang:last_error()` to see a backtrace'

- ——

  1. I tried the ggplot function for one variable (ILproto_1) (univariate qq plot)我为一个变量(ILproto_1)尝试了ggplot函数(单变量qq图)

     ggplot(vdata_clean1, aes(sample = ILproto_1)) + stat_qq() + stat_qq_line() + labs(title= "Normality QQ Plot (ILproto_1)", y = "Sample Quantiles") + theme_classic() `

    => I received this error message: => 我收到此错误消息:

     Don't know how to automatically pick scale for object of type haven_labelled. Defaulting to continuous. Don't know how to automatically pick scale for object of type haven_labelled. Defaulting to continuous. Error in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : polygon edge not found In addition: Warning message: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family "Arial"
      - ——
  2. I also tried a histogram with the ggplot function (for variable ILproto_1)我还尝试了 ggplot 函数的直方图(对于变量 ILproto_1)

     ggp1 <- ggplot(vdata_clean1, aes(x = ILproto_1)) ggp1 <- ggp1 + geom_histogram(binwidth=1, colour="black", aes(y=..density.., fill=..count..)) ggp1 <- ggp1 + scale_fill_gradient("Count", low="#DCDCDC", high="#7C7C7C") ggp1 <- ggp1 + stat_function(fun=dnorm, color="red", args=list(mean=mean(vdata_clean1$ILproto_1), sd=sd(vdata_clean1$ILproto_1))) ggp1

=> There is no error message, but I receive no plot => 没有错误信息,但我没有收到任何情节

It's difficult without a reproducible example.没有可重现的例子是很困难的。 Still, this uses the mtcars dataset to create a dataframe with 11 variables with different variables using ggplot2 .尽管如此,这仍然使用mtcars数据集创建一个包含 11 个变量的数据ggplot2 ,这些变量使用ggplot2

library(tidyr)
library(ggplot2)

mtcars%>%
  gather()%>%
  ggplot(., aes(sample = value)) +
  stat_qq()+
  facet_wrap(vars(key), scales ='free_y')

ggplot2 qqplot 方面

You can look into the mqqnorm function from the {RVAideMemoire} package.您可以查看 {RVAideMemoire} 包中的mqqnorm函数。

It creates a multivariate QQplot based on squared generalized distances and uses chi-square as theoretical distribution.它基于平方广义距离创建一个多元 QQplot,并使用卡方作为理论分布。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM