繁体   English   中英

使用 QQ 图 (R) 比较公猫和母猫的 Pct 分布

[英]Compare the distribution of Pct for male and female cats using a QQ-plot (R)

我必须比较雄性和雌性猫(在同一变量“性别”下)的“Pct”(数据框中的一些变量)的分布。

出现问题是因为我对公猫和母猫的大小观察不同:

    kat %>% group_by(Sex) %>%
        summarize(count = n())
# A tibble: 2 × 2
  Sex   count
  <chr> <int>
1 F        47
2 M        97

只是为了获得更多信息:

head(kat)
  Sex Bwt Hwt       Pct
1   F 2.0 7.0 0.3500000
2   F 2.0 7.4 0.3700000
3   F 2.0 9.5 0.4750000
4   F 2.1 7.2 0.3428571
5   F 2.1 7.3 0.3476190
6   F 2.1 7.6 0.3619048

对于我制作 QQ 图,我知道观察的长度不能不同。

我该怎么办?

我在这里和谷歌都搜索过,但我似乎找不到任何相关信息,因为我一直陷入死胡同。

如果需要解决方案的更多信息,请告诉我。

你能不能像下面那样,计算每个组的一堆相关分位数值,然后将它们相互比较 plot:

library(tidyr)
library(dplyr)
library(ggplot2)
dat <- data.frame(sex=rep(c("male", "female"), c(47, 67)), 
                  pct = rnorm(114, 50, 20))


qdat <- dat %>% 
  group_by(sex) %>% 
  summarise(data.frame(
    pctile = seq(.05, .95, by=.05), 
    q = quantile(pct, seq(.05, .95, by=.05)))) %>% 
  unnest(q) %>% 
  pivot_wider(names_from = "sex", values_from = "q") 
#> `summarise()` has grouped output by 'sex'. You can override using the `.groups`
#> argument.

ggplot(qdat, aes(x=male, y=female)) + 
  geom_point() + 
  geom_abline(intercept=0, slope=1, linetype=2) + 
  theme_classic()

reprex package (v2.0.1) 创建于 2022-11-24

在上面的 plot 中,左下角的点是男性第 5 个百分位值与女性第 5 个百分位值的对比图。 如果它们来自相同的分布,它们应该非常接近 45 度线。

暂无
暂无

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

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