Introduction
Data analysis is an essential and integral part of modern science, technology, and many other areas of human activity. This paper proposes an analysis of the logistic regression method in the R software environment. The ISLR – College dataset is used for evaluation (ISLR, n.d.).
The data will be processed using the GLM function; the processing results will be presented using various visualization tools, including confusion matrices and ROC curves, followed by their interpretation. The project aims to build a model that determines whether a college is private or public using selected predictors. All program code written to implement each task is presented in Appendix A.
Analysis
Data Load and Descriptive Statistics

Initially, data were downloaded for further analysis; for this, the ISLR package was imported to use the College dataset. Loading was provided by the data(College) function. Descriptive statistics for each variable were obtained in Figure 1 using the summary() function. The dim() function showed that this set has 777 rows and 18 columns. Data visualization was carried out using the ggplot2 package.
For example, Figure 2 shows the distribution for the PhD variable, showing the distribution of the percentage of faculties with holders of this degree; here, you can see that the distribution is similar to normal, but shifted to the right. Figure 3 shows the ability to build a scatter diagram – in this example, the dependence of the graduation rate and student/faculty ratio is shown – they offer a weak but inversely proportional dependence.


Training Set
After loading the data and statistically evaluating it with the sample() function, the sample was split into a 70:30 ratio: 70% for model creation and 30% for model testing. The creation of the confusion matrix required preliminary preparation: first, a model was built containing three predictors: the number of students enrolled, room and board costs, and the percentage of teaching staff with PhDs. Next, the predicted variable was created, containing the model’s performance values on the training portion of the sample. It was converted to a factor with two levels: values above 0.5 were treated as 1, and those below 0.5 as 0. This step must match the number of factor levels to build a confusion matrix. Figure 4 shows the result of calling the matrix construction function.

According to the figure, the model correctly predicted the majority of 107 and 381 universities, but not 488. Only 55 turned out to be mispredicted, and most were false negatives – a university to be public according to the model when it is actually private, respectively; these misclassifications are more damaging for the analysis if based on the quantitative aspect. However, this question also depends on the study’s purpose, since the potential to calculate a budget or build a rating based on reputation is at stake. False positives will be more dangerous in the first case, and false negatives in the second.
According to Figure 4, the model achieves 89.87% accuracy across the entire sample, which is a strong result. Precision measures the proportion of correctly predicted positives out of all predicted positives. Figure 4 presents it as Pos Pred Value and shows a value of 69.93%, indicating a higher error due to the high absolute value of false negatives. Sensitivity or recall, indicating the proportion of correctly predicted positives out of all actual positives – extremely high, 92.24%, extremely low probability of error. Specificity is also relatively high – 89.23% and indicates, like recall, a similar ratio, but for negatives.
Testing Set

In this case, in Figure 5, the model was tested on the remaining part of the sample; the results were lower but not significantly so. As before, the number of false negatives outweighs the positives, and all the above accuracy indicators are reduced by only a few percent, which may be due to a smaller data sample. According to the P-values, the results were statistically significant in both cases, as the values are minimal.
ROC Curve and Area Under Curve

Figure 6 shows the ROC curve for the model’s final evaluation on the test set. This graph plots the actual positive rate (sensitivity) against the false positive rate (1 – specificity) at various classification thresholds. It helps evaluate the model’s performance across different thresholds and provides insight into the trade-offs between sensitivity and specificity.
This graph is quite close to the upper-left corner, indicating the model’s predictions are relatively accurate. A quantitative indicator of the interpretation of this graph is the area under the curve, which, according to calculations in R using the performance() function, equals 0.9063438. The AUC represents the probability that a randomly selected positive instance is ranked higher than a randomly selected negative instance by the model (Nahm, 2022).
An ideal model that accurately predicts the outcome is considered to have a value of 1 (Nahm, 2022). Accordingly, according to this assessment, the model with a reasonably high accuracy estimates the categorical variable – whether the university is private or public- by utilizing variables including total student enrollment, room and board fees, and the share of teaching staff with PhD qualifications. Other variables could improve accuracy or increase their inclusion in the regression model; however, at the moment, the results and measured indicators are of high quality.
Conclusion
In this work, using the R language, a model was built and analyzed that determines the type of college – private or public, based on the number of enrolled students, the price of the room and board, and the degree of qualification of the teaching staff of the faculties. The assessment was carried out by constructing a logistic regression model, assessing the dataset using descriptive statistics, dividing it into training and test parts, creating a confusion matrix, evaluating its indicators, constructing a ROC curve, and calculating the area under the curve.
The results were high in many respects. Even though they were slightly lower in the test part than in the training part, the accuracy in both cases exceeds 85%, and the difference is statistically significant. The knowledge we have acquired of the tools and syntax of the R language will allow us in the future to conduct research across various subject areas and to experiment with building a model. Changing the number and variables in the composition of predicates will allow us to evaluate the model’s multiple capabilities on a given sample.
Reference
ISLR – College Data Set (n.d.).
Nahm, F. S. (2022). Receiver operating characteristic curve: Overview and practical use for clinicians. Korean Journal of Anesthesiology, 75(1), 25-36.
Appendix A: R Code
utils:::menuInstallPkgs()
library(‘ISLR’)
summary(College)
data(College)
head(College)
trainIndex <- sort(sample(x = nrow(College), size = nrow(College) * 0.7))
sample_train <- College[trainIndex,]
sample_test <- College[-trainIndex,]
dim(College)
ggplot(data = College, aes(x=PhD))
utils:::menuInstallPkgs()
library(ggplot2)
ggplot(data = College, aes(x=PhD))
ggplot(data = College, aes(x=PhD))+geom_histogram(fill=”steelblue”, color=”black”)
ggplot(data = College, aes(x=S.F.Ratio, y=Grad.Rate))+geom_boxplot(fill=”steelblue”, color=”black”)
ggplot(data = College, aes(x=S.F.Ratio, y=Grad.Rate))+geom_point()
utils:::menuInstallPkgs()
library(stats)
utils:::menuInstallPkgs()
library(caret)
data(College)
trainIndex <- sort(sample(x = nrow(College), size = nrow(College) * 0.7))
sample_train <- College[trainIndex,]
sample_test <- College[-trainIndex,]
model <- glm(Private ~ Enroll + Room.Board + PhD, data = sample_train, family = binomial)
sample_train$Private <- ifelse(sample_train$Private==”Yes”, 1, 0)
sample_train1 <- as.factor(sample_train$Private)
predicted <- predict(model, sample_train, type = “response”)
predicted<-ifelse(predicted> 0.5,1,0)
predicted <- as.factor(predicted)
confusionMatrix(sample_train1,predicted)
model <- glm(Private ~ Enroll + Room.Board + PhD, data = sample_test, family = binomial)
predicted <- predict(model, sample_test, type = “response”)
predicted<-ifelse(predicted> 0.5,1,0)
predicted <- as.factor(predicted)
sample_test2 <- ifelse(sample_test$Private==”Yes”,1,0)
sample_test2 <- as.factor(sample_test2)
confusionMatrix(sample_test2,predicted)
utils:::menuInstallPkgs()
library(ROCR)
pred <- predict(model, newdata=sample_test, type=”response”)
pred_obj <- prediction(pred, sample_test$Private)
roc_obj <- performance(pred_obj,”tpr”,”fpr”)
plot(roc_obj, mail=”ROC Curve”)
auc_value <- performance(pred_obj, “auc”)@y.values[[1]]
auc_value