簡體   English   中英

如何在重復測量設計中獲取長格式數據的直方圖得分

[英]How to get the scores in a long-format data for histogram in the repeated-measures design

我使用melt()將數據從寬格式轉換為長格式,並顯示了我的長格式數據(df),如下所示:

Participant Tests Scores  
1 A 8  
1 B 7  
1 C 1  
1 D 6  
2 A 9  
2 B 5  
2 C 2  
2 D 5  
3 A 6  
3 B 2  
3 C 3  
3 D 8  
4 A 5  
4 B 3  
4 C 1  
4 D 9  
5 A 8  
5 B 4  
5 C 5  
5 D 8  
6 A 7  
6 B 5  
6 C 6  
6 D 7  

如何獲得df$Tests[1]所有分數(即,每個參加測試的人= A)?

此外,如果我希望繪制直方圖,例如:

hist.TestA <- ggplot(df, aes(???)) + theme(legend.position = "none") + geom_histogram(aes(y=..density..), colour="black", fill="white", binwidth = 1) + labs(x="Test A", y = "Density") + stat_function(fun = dnorm, args = list(mean = mean(???, na.rm = TRUE), sd = sd(???, na.rm = TRUE)), colour = "black", size = 1)

但我不知道我在“ ???”字段中寫了什么 在上述語法中。

先感謝您。

最好。

您可以執行以下操作以獲取分數或僅給出給定Test的數據子集

data <- data.frame(
    Participant= c(1, 1, 1, 1, 2, 2, 2, 2),
    Tests = c("A", "B", "C", "D", "A", "B", "C", "D"),
    Scores = c(8, 7, 1, 6, 9, 5, 2, 5)
)

sub <- by(data = data, INDICES = data$Tests, FUN = c)

尚不清楚您嘗試使用ggplot做什么,但是如果您想為每個測試繪制直方圖,可以這樣做:

hist(x = sub$A$Scores, freq = FALSE, xlab = "Scores", main = "Test A")

或與ggplot

ggplot(data, aes(x=Scores, color=Tests, fill=Tests)) +
    geom_histogram(aes(y=..density..), position="identity", alpha=0.5, bins=10)

簡單的方差分析圖可以按照以下步驟完成:

ggplot(data, aes(x = Tests, y = Scores)) +
  geom_boxplot(fill = "grey80", colour = "blue") +
  scale_x_discrete() + xlab("Treatment Group") +
  ylab("Dried weight of plants")

有關方差分析和繪圖的更多信息,請參見本教程

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM