简体   繁体   English

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

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

I have to compare the distribution of "Pct" (some variabel in the data frame) for male and female cats (which are under the same variabel "Sex").我必须比较雄性和雌性猫(在同一变量“性别”下)的“Pct”(数据框中的一些变量)的分布。

The problem occurs because i there are different size observations of male and female cats:出现问题是因为我对公猫和母猫的大小观察不同:

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

Just for some more information:只是为了获得更多信息:

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

For me to make a QQ-plot i know the length of observations must not differ.对于我制作 QQ 图,我知道观察的长度不能不同。

What do i do?我该怎么办?

I have both searched here and Google, but i can't seem to find any relevant information because i keep running into a dead end.我在这里和谷歌都搜索过,但我似乎找不到任何相关信息,因为我一直陷入死胡同。

Please let me know if more information for the solution is required.如果需要解决方案的更多信息,请告诉我。

Could you do like below, where you calculate a bunch of relevant quantile values for each group and then plot them against each other:你能不能像下面那样,计算每个组的一堆相关分位数值,然后将它们相互比较 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()

Created on 2022-11-24 by the reprex package (v2.0.1)reprex package (v2.0.1) 创建于 2022-11-24

In the plot above, the point in the lower-left corner is the value of the 5th percentile for males plotted against the 5th percentile value for females.在上面的 plot 中,左下角的点是男性第 5 个百分位值与女性第 5 个百分位值的对比图。 If they come from the same distribution, they should be pretty close to the 45-degree line.如果它们来自相同的分布,它们应该非常接近 45 度线。

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

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