美文网首页
R学习笔记 分组对连续变量进行统计描述

R学习笔记 分组对连续变量进行统计描述

作者: 扩容_ | 来源:发表于2019-10-17 21:43 被阅读0次

    1、describeBy()、aggregate()

    myvar4 <- c("GENDR","RACE","Height")
    data4 <- a[myvar4]
    library(psych)
    attach(data4)
    describeBy(Height,list(GENDR=GENDR,RACE=RACE))
    means <- aggregate(Height,by=list(GENDR,RACE),FUN=mean,na.rm=TRUE)
    detach()
    

    2、barplot()、qqPlot()

    #第一种条形图
    means$Group.2 <- as.character(means$Group.2)
    barplot(x~Group.2+Group.1,means,xlab="GENDR",
            col = c("red","yellow","green","blue","black"),
            beside=TRUE,ylim=c(0,180),
            legend.text=c("RACE1","RACE2","RACE3","RACE4","RACE5"))
    
    #第二种条形图
    data4_1 <- subset(data4,GENDR==1)
    attach(data4_1)
    means_1 <- subset(means,Group.1==1)
    barplot(x~Group.2,means_1,xlab="RACE")
    detach()
    data4_2 <- subset(data4,GENDR==2)
    attach(data4_2)
    means_2 <- subset(means,Group.1==2)
    barplot(x~Group.2,means_2,xlab="RACE")
    detach()
    install.packages("car")
    library(car)
    qqPlot(lm(Height~RACE,data=data4_1),simulate=TRUE,main="Q-Q Plot",labels=FALSE)
    

    相关文章

      网友评论

          本文标题:R学习笔记 分组对连续变量进行统计描述

          本文链接:https://www.haomeiwen.com/subject/iqcbmctx.html