医学统计与R语言:aggregate.plot了解一下

2020-07-06 17:29:08 浏览数 (1)

输入1:

代码语言:javascript复制
longrma <- read.csv("longrma.csv",header=T)
longrma[sample(nrow(longrma),,replace=F),]

结果1:

代码语言:javascript复制
    id     group   time   score
  treatment  after    
  treatment  after    
     control before    
    control  after    
   treatment before    
    treatment middle    
  treatment  after    
     control before    
     treatment before    
    control middle    

输入2:

代码语言:javascript复制
longrma$group <- factor(longrma$group,levels = c("control","treatment"))
longrma$time <- factor(longrma$time,levels = c("before","middle","after"))
install.packages(epiDisplay)
library(epiDisplay)
attach(longrma)
aggregate.plot(x=score,by=list(group=group,time=time), FUN="mean",error="ci",
               lwd=, line.col = "black",alpha=0.05,
               legend.site = "topleft", bar.col = c("red","blue")) 

结果2:

代码语言:javascript复制

输入3:

代码语言:javascript复制
longrma$time <- ifelse(longrma$time=="before",, ifelse(longrma$time=="middle",,))
longrma$time <- as.numeric(longrma$time)
attach(longrma)
aggregate.plot(x=score,by=time,grouping=group,FUN="mean",error="ci",
               lwd=,line.col=c("black","red"))
detach(longrma)

When 'by' is of class 'factor', a bar plot with error bars is displayed. When 'by' is a continuous variable (typically implying time), a time line graph is displayed.

0 人点赞