楼主: dazzlingpuck
1841 0

[问答] R语言回归系数拟方差函数qvcalc()报错:参数长度为零 [推广有奖]

  • 1关注
  • 0粉丝

硕士生

98%

还不是VIP/贵宾

-

威望
0
论坛币
12 个
通用积分
16.0120
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
10832 点
帖子
34
精华
0
在线时间
384 小时
注册时间
2013-10-5
最后登录
2024-3-19

楼主
dazzlingpuck 发表于 2019-10-1 23:54:26 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
因为需要对分类变量不同组别的效应进行作图比较,用到qvcalc函数(回归分析中分类变量中各组通常只与参照组对比)。
按help中的例子用glm来做是没有问题的,数据集为R包里的"ships":
  1. library(qvcalc)
  2. ships <- read.csv(file = "/Users/ships.csv", header = TRUE)
  3. ships$year <- as.factor(ships$year)
  4. ships$period <- as.factor(ships$period)
  5. shipmodel <- glm(formula = incidents ~ type + year + period,
  6.                  family = quasipoisson,
  7.                  data = ships,
  8.                  subset = (service > 0),
  9.                  offset = log(service))
  10. shiptype.qvs <- qvcalc(shipmodel, "type")
  11. summary(shiptype.qvs, digits = 4)
  12. plot(shiptype.qvs, xlab = "ship type")
复制代码

但是用比例风险模型时总是报错,因变量是factor类型,不知道哪里出了问题:
Error in if (n <= 2) stop("qvcalc works only for factors with 3 or more levels") :
  参数长度为零
数据集为R包里的"veteran":
  1. library(survival)
  2. veteran <- read.csv(file = "/Users/veteran.csv", header = TRUE)
  3. cancermodel<-coxph(Surv(time,status)~celltype,data=veteran,x=T)
  4. cancercelltype.qvs <- qvcalc(cancermodel, "celltype")
复制代码
ships & veteran.zip (2.98 KB) 本附件包括:
  • veteran.csv
  • ships.csv


不同文献都提到qvcalc函数可以应用于比例风险模型:
The function qvcalc may be appliedto R objects of class lm (linear regressions), glm (generalized linear models), polr (orderedlogit or ‘proportional odds’ models), coxph (proportional hazards models), survreg (parametric survival models), gls (linear models fit by generalized least squares), lme (linearmixed-effect models, e.g., for hierarchical and longitudinal data) and others.

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝


您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-2-7 19:18