[英]Creating multivariate Q-Q Plots in R
我希望用 R 中的 QQ 圖測試多元和單變量正態性。我使用了幾種不同的方法 - 它們似乎都不起作用。 我是 R 的新手,對任何幫助都會非常感激。
我的數據集 = vdata_clean1
我有 15 個預測變量 (IV),但沒有響應變量 (DV),因為我正在運行驗證性因子分析(這 15 個變量代表構成我正在測試的量表的 15 種不同類型的項目)。
我已經安裝了以下軟件包:
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")
首先,我使用了 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)
=> 我沒有收到錯誤消息,但沒有顯示圖。
——
二、嘗試了qqnorm函數(多元qq圖)
qqnorm(vdata_clean1, ylim, main = "Normal QQ Plot", xlab = "Theoretical Quantiles", ylab = "Sample Quantiles", plot.it = TRUE, datax = FALSE)
=> 我收到以下錯誤消息,但沒有圖表:
Error: Must use a vector in `[`, not an object of class matrix. Call `rlang:last_error()` to see a backtrace'
——
我為一個變量(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() `
=> 我收到此錯誤消息:
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"
我還嘗試了 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
=> 沒有錯誤信息,但我沒有收到任何情節
您可以查看 {RVAideMemoire} 包中的mqqnorm函數。
它基於平方廣義距離創建一個多元 QQplot,並使用卡方作為理論分布。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.