我的数据集中的有条件分组的直方图

发布于 2024-08-06 15:38:20 字数 1365 浏览 12 评论 0原文

我当前的数据集 data.df 来自大约 420 名学生,他们在 3 名讲师之一的指导下完成了包含 8 个问题的调查。 escore 是我感兴趣的结果变量。


    'data.frame':   426 obs. of  10 variables:
     $ ques01: int  1 1 1 1 1 1 0 0 0 1 ...
     $ ques02: int  0 0 1 1 1 1 1 1 1 1 ...
     $ ques03: int  0 0 1 1 0 0 1 1 0 1 ...
     $ ques04: int  1 0 1 1 1 1 1 1 1 1 ...
     $ ques05: int  0 0 0 0 1 0 0 0 0 0 ...
     $ ques06: int  1 0 1 1 0 1 1 1 1 1 ...
     $ ques07: int  0 0 1 1 0 1 1 0 0 1 ...
     $ ques08: int  0 0 1 1 1 0 1 1 0 1 ...
     $ inst  : Factor w/ 3 levels "1","2","3": 1 1 1 1 1 1 1 1 1 1 ...
     $ escore: int  3 1 5 5 3 3 4 4 2 5 ...
     

我想知道如何生成 escore 直方图,这些直方图根据给定观察的 inst 值有条件地分离。在我看来,伪代码可能如下所示:


    par(mfrow=c(1,3)) 
    hist(escore, data.df$inst = 1)
    hist(escore, data.df$inst = 2)
    hist(escore, data.df$inst = 3)

但这当然行不通:-(

理想情况下,我的直方图如下所示:

3 个独立的直方图,每个直方图约 140 个观测值,根据其“inst”值进行分组 http://terpconnect.umd.edu/~briandk/escoreHistogramsbyInstructor-1.png

像往常一样,我觉得必须有一个在任何“条件/分组”意义上,我都可以从我的数据中提取这些图表,我认为它可以概括为您想要基于的各种图表。 另外,如果这个问题之前已经得到解答,我真的很抱歉,

我的主要困难是如何以有意义的方式提出这个问题,

谢谢您的帮助!

My current dataset data.df comes from about 420 students who took an 8-question survey under one of 3 instructors. escore is my outcome variable of interest.


    'data.frame':   426 obs. of  10 variables:
     $ ques01: int  1 1 1 1 1 1 0 0 0 1 ...
     $ ques02: int  0 0 1 1 1 1 1 1 1 1 ...
     $ ques03: int  0 0 1 1 0 0 1 1 0 1 ...
     $ ques04: int  1 0 1 1 1 1 1 1 1 1 ...
     $ ques05: int  0 0 0 0 1 0 0 0 0 0 ...
     $ ques06: int  1 0 1 1 0 1 1 1 1 1 ...
     $ ques07: int  0 0 1 1 0 1 1 0 0 1 ...
     $ ques08: int  0 0 1 1 1 0 1 1 0 1 ...
     $ inst  : Factor w/ 3 levels "1","2","3": 1 1 1 1 1 1 1 1 1 1 ...
     $ escore: int  3 1 5 5 3 3 4 4 2 5 ...
     

I'm wondering how I can generate escore histograms that are conditionally separated based upon the value of inst for a given observation. In my head, the pseudo-code might look like this:


    par(mfrow=c(1,3)) 
    hist(escore, data.df$inst = 1)
    hist(escore, data.df$inst = 2)
    hist(escore, data.df$inst = 3)

but of course that won't work :-(

Ideally, my histograms would look like this:

3 separate histograms of ~140 observations each, grouped according to their "inst" value http://terpconnect.umd.edu/~briandk/escoreHistogramsbyInstructor-1.png

As usual, I sense there's got to be an easy way to do this. In whatever "conditional/grouping" sense I can extract these graphs from my data, I assume it's got to be generalizable for all sorts of plots you'd want to make based on certain conditions.

Also, I'm really sorry if this question has been answered before. My primary difficulty is in figuring out how to ask it in a way that makes sense.

Thanks in advance for your help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

花心好男孩 2024-08-13 15:38:20

使用lattice包:

library(lattice)
histogram( ~ escore | inst, data=X)

如果X是你的data.frame对象。

Use the lattice package:

library(lattice)
histogram( ~ escore | inst, data=X)

if X is your data.frame object.

嗼ふ静 2024-08-13 15:38:20

您也可以在 ggplot2 中执行此操作:

data.df <- data.frame(inst = factor(sample(3, 426, replace=TRUE)), 
                      escore = sample(5, 426, replace=TRUE))
qplot(escore, fill=inst, data=data.df) + facet_wrap(~inst, ncol=3)

alt text http://www.cs.princeton.edu/~jcone/历史记录.png

You can also do this in ggplot2:

data.df <- data.frame(inst = factor(sample(3, 426, replace=TRUE)), 
                      escore = sample(5, 426, replace=TRUE))
qplot(escore, fill=inst, data=data.df) + facet_wrap(~inst, ncol=3)

alt text http://www.cs.princeton.edu/~jcone/hists.png

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文