data(iris)
model <- lm(Petal.Length ~ Sepal.Length + Sepal.Width, data = iris)
summary(model)
##
## Call:
## lm(formula = Petal.Length ~ Sepal.Length + Sepal.Width, data = iris)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.25582 -0.46922 -0.05741 0.45530 1.75599
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -2.52476 0.56344 -4.481 1.48e-05 ***
## Sepal.Length 1.77559 0.06441 27.569 < 2e-16 ***
## Sepal.Width -1.33862 0.12236 -10.940 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.6465 on 147 degrees of freedom
## Multiple R-squared: 0.8677, Adjusted R-squared: 0.8659
## F-statistic: 482 on 2 and 147 DF, p-value: < 2.2e-16
library(mlbench)
library(pROC)
## Type 'citation("pROC")' for a citation.
##
## Attaching package: 'pROC'
## The following objects are masked from 'package:stats':
##
## cov, smooth, var
# Load dữ liệu bệnh tim
data(PimaIndiansDiabetes)
Heart <- PimaIndiansDiabetes
# Xây dựng mô hình logistic
model_logit <- glm(diabetes ~ ., data = Heart, family = binomial)
# Dự đoán xác suất
prob <- predict(model_logit, type = "response")
# Vẽ ROC
roc_obj <- roc(Heart$diabetes, prob)
## Setting levels: control = neg, case = pos
## Setting direction: controls < cases
plot(roc_obj, main="ROC Curve")

# Tính AUC
auc(roc_obj)
## Area under the curve: 0.8394