数据说明
基于抖音系列第二轮活动各关卡进度记录数据(2022年8月8日~8月14日,即8月第二周)
读取数据与展示
library(readxl) # install.packages("readxl", repos = "https://mirrors.ustc.edu.cn/CRAN/") df=read_xlsx('./data//回归分析.xlsx') # 查看数据 df %>% DT::datatable(extensions = 'Buttons', options = list(dom = 'Blfrtip', buttons = c('copy', 'csv', 'excel', 'pdf', 'print'), lengthMenu = list(c(10,25,50,-1), c(10,25,50,"All"))))
数据描述性统计分析与绘图
统计
planes <- group_by(df,关卡) delay <- summarise(planes, 数据量 = n(), #个数 使用骰子数量 = max(次数), #最大值, `各关卡进度(%)` = max(进度) #最大值 ) delay
从统计结果可知,目前关卡1~4进度均已完成(使用骰子数量分别为13、14、57、204),关卡5使用骰子253次进度完成26.83%
绘图
library(ggplot2) df$关卡<-factor(df$关卡) ggplot(data=df,aes(x = 序号, y = 进度))+ geom_point()+xlim(0,600)+aes(colour=关卡)+xlab("累计次数")+ylab("进度(%)")+ coord_fixed(ratio = 3)+ ggtitle(label='骰子使用次数与各关卡进度的关系',subtitle = NULL)+ theme(plot.title = element_text(#color = 'red', size=15, hjust=0.5), plot.caption = element_text(color='blue'))
关卡5回归分析
建立回归模型
library(dplyr) df5<- filter(df, 关卡 == 5) fit5<-lm(data=df5,进度~次数) summary(fit5)
分析模型可以看出关卡5使用骰子次数与进度的关系为:y=0.1060725*x-0.2021598
当y=100时,可计算得到x=944.657284404535
可视化绘图
par(pin = c(6,4)) plot(df5$次数,df5$进度, xlab="骰子次数(实际次数或预估次数)", ylab="进度(%)", xlim=c(0,1000),ylim=c(0,100), main="关卡5需要的骰子数量", col=c('red') ) abline(fit5) abline(h=100) abline(v=945) text(x = 700,y = 63,labels = 'y=0.1060725*x-0.2021598') text(x = 955,y = 50,labels = 'x=945')
关卡5与累计骰子使用次数回归分析(关卡1~5使用骰子数量)
建立回归模型
fit<-lm(data=df5,进度~序号) summary(fit)
分析模型可以看出关卡5使用骰子次数与进度的关系为:y=1.061e-01*x--3.075e+01
当y=100时,可计算得到x=1232.32799245994
可视化绘图
par(pin = c(6,4)) plot(df$序号,df$进度, xlab="累计次数(实际或预估次数)", #x轴名称 ylab="进度(%)", #y轴名称 xlim=c(0,1500),ylim=c(0,100), main="累计骰子使用次数与进度的关系", col=df$关卡 ) abline(h=100) abline(fit) abline(v=1232) text(x = 900,y = 63,labels = 'y=1.061e-01*x--3.075e+01') text(x = 1232,y = 50,labels = 'x=1232') legend(1300,95,inset = 0.04,c(paste0("关卡", 1:5)),pch = c(1), col = c("black","red","chartreuse","blue","aquamarine4"),box.col = "red", title="关卡", box.lwd = 2,text.font = 1)
结论
关卡5大约需要使用骰子数量为945,完成1~5关卡则需要使用骰子数量为1232。