首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在R中绘制卡方QQ图中的QQ线

在R中绘制卡方QQ图中的QQ线
EN

Stack Overflow用户
提问于 2019-03-31 03:12:14
回答 1查看 2.3K关注 0票数 0

我将下面的代码复制到r help中。但是,qqline函数不起作用。原因何在?

代码语言:javascript
复制
library(mgcViz)
y <- rchisq(500, df = 3)
## Q-Q plot for Chi^2 data against true theoretical distribution:
qqplot(qchisq(ppoints(500), df = 3), y, main = expression("Q-Q plot for" ~~ {chi^2}[nu == 3]))
qqline(y, distribution = function(p) qchisq(p, df = 3), prob = c(0.1, 0.6), col = 2)

谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-03-31 03:53:54

要使用mgcViz添加qqline,您需要使用ggplot:

代码语言:javascript
复制
library(mgcViz)
y <- rchisq(500, df = 3)
## Q-Q plot for Chi^2 data against true theoretical distribution:
qqplot(qchisq(ppoints(500), df = 3), y, main = expression("Q-Q plot for" ~~ {chi^2}[nu == 3]))

# Add qq line
library(ggplot2)
ggplot2::last_plot() + qqline(y, distribution = function(p) qchisq(p, df = 3), prob = c(0.1, 0.6), col = 2)

要查看qqline的截距和斜率,可以执行以下操作:

代码语言:javascript
复制
my.qqline = qqline(y, distribution = function(p) qchisq(p, df = 3), prob = c(0.1, 0.6), col = 2)
> my.qqline$data
   intercept     slope
1 0.08606285 0.9290453
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55434852

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档