留一法交叉验证 GLM 模型
Leave-one-out cross validation GLM model
我正在尝试通过首先将我的数据拟合到 glm 模型,然后使用预测来进行留一法交叉验证。显然我没有正确设置交叉验证,因为我收到错误。谁知道这应该怎么写才正确?
data <- structure(list(hsa_miR_1306_5p = c(5.66281697186733, 6.58664110311681,
8.24680160610849, 7.59469600671128, 5.11353374464181, 5.21216070738553
), hsa_miR_576_5p = c(3.01744918102835, 4.94428256624179, 6.47085031132479,
6.341071987735, 5.11353374464181, 4.94239499718096), V3 = c(3,
5, 3, 3, 5, 5), V4 = c(29.9, 27.1, 32.7, 24.9, 30.2, 29.9), V5 = c(1957,
1948, 1951, 1954, 1946, 1952), V6 = c(1, 1, 1, 0, 1, 0)), row.names = c("1004773522",
"1108651363", "1170306251", "1170306252", "1170306253", "1170306258"
), class = "data.frame")
LOOCV 模型:
loocv <- sapply(1:nrow(data), function(x) {
loo.data <- data[-x,]
model <- glm(as.factor(V3) ~ hsa_miR_1306_5p + hsa_miR_576_5p + V4 + V5 + V6, family=binomial(logit),data=loo.data)
predict(model,newdata=data[x,], type = "lp")
})
剧情:
roc.data <-roc(model$y , model$fitted.values,ci=T,predictor = loocv)
plot.roc(roc.data)
错误:
Error in match.arg(type) :
'arg' should be one of “link”, “response”, “terms”
您需要小心使用您所使用的软件包。请在分析之前加载两个包:
library(pROC)
library(rms)
基础 R predict(或 predict.glm)函数有一个类型参数,但只有选项
type = c("link", "response", "terms")
您通过指定
获得线性预测变量
predict(..., type = "link")
您使用的语法来自 rms::predictrms() 函数。
我正在尝试通过首先将我的数据拟合到 glm 模型,然后使用预测来进行留一法交叉验证。显然我没有正确设置交叉验证,因为我收到错误。谁知道这应该怎么写才正确?
data <- structure(list(hsa_miR_1306_5p = c(5.66281697186733, 6.58664110311681,
8.24680160610849, 7.59469600671128, 5.11353374464181, 5.21216070738553
), hsa_miR_576_5p = c(3.01744918102835, 4.94428256624179, 6.47085031132479,
6.341071987735, 5.11353374464181, 4.94239499718096), V3 = c(3,
5, 3, 3, 5, 5), V4 = c(29.9, 27.1, 32.7, 24.9, 30.2, 29.9), V5 = c(1957,
1948, 1951, 1954, 1946, 1952), V6 = c(1, 1, 1, 0, 1, 0)), row.names = c("1004773522",
"1108651363", "1170306251", "1170306252", "1170306253", "1170306258"
), class = "data.frame")
LOOCV 模型:
loocv <- sapply(1:nrow(data), function(x) {
loo.data <- data[-x,]
model <- glm(as.factor(V3) ~ hsa_miR_1306_5p + hsa_miR_576_5p + V4 + V5 + V6, family=binomial(logit),data=loo.data)
predict(model,newdata=data[x,], type = "lp")
})
剧情:
roc.data <-roc(model$y , model$fitted.values,ci=T,predictor = loocv)
plot.roc(roc.data)
错误:
Error in match.arg(type) :
'arg' should be one of “link”, “response”, “terms”
您需要小心使用您所使用的软件包。请在分析之前加载两个包:
library(pROC)
library(rms)
基础 R predict(或 predict.glm)函数有一个类型参数,但只有选项
type = c("link", "response", "terms")
您通过指定
获得线性预测变量predict(..., type = "link")
您使用的语法来自 rms::predictrms() 函数。