vgam(formula=c$Mortality~c$Group+s(c$Age,df=3),family = binomialff(link = "logitlink"),
时间: 2024-05-25 20:17:47 浏览: 24
data = c)
The vgam function is used for fitting a generalized additive model (GAM) with a binomial family and a logit link function. In this case, the response variable is c$Mortality and the predictor variable is c$Age, which is modeled as a smooth function of the Group variable with 3 degrees of freedom. The data is provided in the c dataframe.
相关问题
ggplot()+ geom_histogram(binwidth = 200,data=data,aes(x=SII,y=..count..),alpha = 0.8,colour="gold3",fill="gold3")+ scale_y_continuous(sec.axis = sec_axis(~./80, name = "HR (95%CI) for 2-year all-cause mortality"))+ geom_line(data=HR, aes(SII,yhat*80), linetype="solid",size=1,alpha = 0.7,colour="steelblue1")+ geom_ribbon(data=HR, aes(SII,ymin = lower*80, ymax = upper*80), alpha = 0.1,fill="blue")+ theme_classic()+ geom_hline(yintercept=1*80, linetype=2,size=1)+ geom_vline(xintercept=570,size=1,linetype=2,color = '#d40e8c')+ geom_vline(xintercept=1010,size=1,linetype=2,color = '#d40e8c')+#查表HR=1对应的age labs(x="Systemic immune-inflammation index", y="Count")+ xlim(0,3500)+ labs(title = " ")+ theme(plot.title = element_text(hjust = 0.5))
这是一段 R 代码,使用 ggplot2 包进行数据可视化。首先使用 geom_histogram 函数绘制直方图,binwidth 参数设置直方图的宽度,data 参数指定数据集,aes 函数设置 x 轴为 SII,y 轴为计数,alpha 参数设置透明度,colour 参数设置边框颜色,fill 参数设置填充颜色。然后使用 scale_y_continuous 函数设置 y 轴的第二个坐标轴,sec.axis 参数指定第二个坐标轴,~./80 表示原坐标轴除以 80,name 参数设置坐标轴名称。接着使用 geom_line 函数绘制折线图,data 参数指定数据集,aes 函数设置 x 轴为 SII,y 轴为 yhat*80,linetype 参数设置线型,size 参数设置线宽,alpha 参数设置透明度,colour 参数设置颜色。使用 geom_ribbon 函数绘制带状图,data 参数指定数据集,aes 函数设置 x 轴为 SII,ymin 参数设置下限,ymax 参数设置上限,alpha 参数设置透明度,fill 参数设置填充颜色。使用 theme_classic 函数设置主题样式,geom_hline 函数绘制水平参考线,yintercept 参数设置纵坐标值,linetype 参数设置线型,size 参数设置线宽度。geom_vline 函数绘制竖直参考线,xintercept 参数设置横坐标值,size 参数设置线宽度,linetype 参数设置线型,color 参数设置颜色。最后使用 labs 函数设置图例和坐标轴标签,xlim 函数设置 x 轴的最小值和最大值,labs 函数设置标题,theme 函数设置主题。
> ggplot()+ + geom_histogram(binwidth = 200,data=data,aes(x=SII,y=..frequency..),alpha = 0.8,colour="gold3",fill="gold3")+ + scale_y_continuous(sec.axis = sec_axis(~.*4000, name = "HR (95%CI) for 2-year all-cause mortality"))+ + geom_line(data=HR, aes(SII,yhat/4000), + linetype="solid",size=1,alpha = 0.7,colour="steelblue1")+ + geom_ribbon(data=HR, + aes(SII,ymin = lower/4000, ymax = upper/4000), + alpha = 0.1,fill="blue")+ + theme_classic()+ + geom_hline(yintercept=1/4000, linetype=2,size=1)+ + geom_vline(xintercept=570,size=1,linetype=2,color = '#d40e8c')+ + geom_vline(xintercept=1000,size=1,linetype=2,color = '#d40e8c')+#查表HR=1对应的age + labs(x="Systemic immune-inflammation index", y="Density")+ + xlim(0,4000)+ + labs(title = " ")+ + theme(plot.title = element_text(hjust = 0.5)) Error in `geom_histogram()`: ! Problem while mapping stat to aesthetics. ℹ Error occurred in the 1st layer. Caused by error in `map_statistic()`: ! Aesthetics must be valid computed stats. ✖ The following aesthetics are invalid: ✖ `y = ..frequency..` ℹ Did you map your stat in the wrong layer? Run `rlang::last_error()` to see where the error occurred. Warning messages: 1: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0. ℹ Please use `linewidth` instead. This warning is displayed once every 8 hours. Call `lifecycle::last_lifecycle_warnings()` to see where this warning was generated. 2: The dot-dot notation (`..frequency..`) was deprecated in ggplot2 3.4.0. ℹ Please use `after_stat(frequency)` instead. This warning is displayed once every 8 hours. Call `lifecycle::last_lifecycle_warnings()` to see where this warning was generated. 3: Removed 70 rows containing non-finite values (`stat_bin()`).
这段代码中出现了一些错误,其中一个是出现了无效的映射。具体而言,`y = ..frequency..` 这个映射是无效的,应该使用 `y = after_stat(frequency)`。另外,也出现了一些警告信息,例如 `size` 映射被弃用了,应该使用 `linewidth`。还有一个警告是有70个行包含了非有限值(`stat_bin()`)。这些问题需要修改才能正常运行代码。
阅读全文