显示与人口百分位数相关的分数的适当方法

时间:2017-08-21 08:34:51

标签: r excel graph comparison spss

我有一个包含8个变量和超过300个观察(参与者)的数据集。这些观察结果随机分为10组。每个参与者执行相同的任务集。

对于每个小组,我想绘制一个图表,说明他们在平均分数落在整体百分位数方面的表现。

我做了一些谷歌搜索,发现下面的图表。这是一组参与者的图表,每个条形代表一个任务。 性能标签是通过将(每个任务的)总分(分为10%,20%,40%,20%,10%)分别产生的。

有没有办法在R,SPSS或Excel中绘制它?

由于

enter image description here

1 个答案:

答案 0 :(得分:1)

在R中你可以这样做:

a=c(0.1,0.4,0.5,0.6,0.9)
# a containes the result per category in a vector

barplot(a, names.arg=c("Cat1", "Cat2", 
"Cat3","Cat4","Cat5"),horiz=TRUE,xlim=c(0,1),ylim=c(0,6.5))

# add the vertical lines
abline(v=c(0.25,0.5,0.75),col='red')

# add the text
text(0.1, y =6.3, labels = 'Low')
text(0.4, y =6.3, labels = 'Average')
text(0.6, y =6.3, labels = 'High')
text(0.85, y =6.3, labels = 'Very high')

输出如下所示:Results of the test per category

非常基本,但如果你愿意,可以进一步自定义。

编辑:添加代码以计算不同类别的分位数。我假设你有一个带有2列的R数据帧,1个结果名称" col"和一个包含名为category的类别。

然后这段代码就可以了:

# df is the dataframe in which your data are stored
all_categories = unique(df$category)

N=length(all_categories)
results_category=rep(0,N)
# q is the percentile you have to compute 0.5 is the median
q_wanted=0.5

for (i in (1:N)){
  results_category[i] = quantile(x=df$col[df$category==all_categories[i]],prob=q_wanted)
}

barplot(results_category, 
names.arg=all_categories,horiz=TRUE,xlim=c(0,1),ylim=c(0,5))
abline(v=c(0.25,0.5,0.75),col='red')
text(0.1, y =4, labels = 'Low')
text(0.4, y =4, labels = 'Average')
text(0.6, y =4, labels = 'High')