留一法交叉验证GLM模型

我尝试通过先将数据拟合到glm模型,然后使用predict函数来进行留一法交叉验证。显然,我没有正确设置交叉验证,因为我得到了一个错误。有人知道这应该如何正确编写吗?

 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'应该在“link”, “response”, “terms”之一

回答:

你需要注意你使用的包。在进行分析之前请加载这两个包:

library(pROC)library(rms)

基础R的predict(或predict.glm)函数有一个type参数,但只有以下选项

type = c(“link”, “response”, “terms”)

你可以通过指定

predict(..., type = "link")

来获取线性预测值。你使用的语法来自于rms::predictrms()函数。

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注