0% found this document useful (0 votes)
0 views6 pages

YuvaIntern Week3 R Data Analyst Report

This report details the Week 3 activities of the YuvaIntern Virtual R Data Analyst Internship, focusing on statistical analysis and predictive modeling of Titanic passenger survival. It includes hypothesis testing, correlation analysis, and the development of a logistic regression model to predict survival based on various passenger characteristics. The model's performance is evaluated using confusion matrices and ROC curves, with suggestions for future improvements outlined.

Uploaded by

seyedubuhari
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views6 pages

YuvaIntern Week3 R Data Analyst Report

This report details the Week 3 activities of the YuvaIntern Virtual R Data Analyst Internship, focusing on statistical analysis and predictive modeling of Titanic passenger survival. It includes hypothesis testing, correlation analysis, and the development of a logistic regression model to predict survival based on various passenger characteristics. The model's performance is evaluated using confusion matrices and ROC curves, with suggestions for future improvements outlined.

Uploaded by

seyedubuhari
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

YuvaIntern – Virtual R Data Analyst Internship

Week 3 Report: Statistical Analysis and Predictive Modeling using R


Project: Titanic Passenger Survival Analysis and Prediction Using R

1. Introduction
This report presents the Week 3 statistical analysis and predictive modeling work completed as part of the YuvaIntern
Virtual R Data Analyst Internship. The Titanic passenger dataset used in Weeks 1 and 2 is continued in order to
perform hypothesis testing, correlation analysis, and predictive modeling. The primary modeling objective is to
predict whether a passenger survived based on selected demographic and travel-related variables.

2. Dataset and Preparation


The dataset contains the survival outcome along with passenger class, sex, age, family-related variables, fare, and
embarkation port. Missing age values are replaced with the median and missing embarkation values are handled
using the mode. Categorical variables are converted into factors. Only variables relevant to the statistical and
predictive analysis are retained.

3. Hypothesis Testing
Two statistical tests are included. First, an independent samples t-test is used to examine whether the mean age
differs between passengers who survived and passengers who did not survive. The null hypothesis states that the two
group means are equal, while the alternative hypothesis states that they are different. Second, a chi-square test of
independence is used to evaluate whether survival outcome and sex are associated.

4. Correlation Analysis
Correlation coefficients are calculated among numerical variables including age, number of siblings or spouses,
number of parents or children, and fare. This provides an initial assessment of linear relationships between numerical
predictors and helps identify variables that may contain related information.

5. Train-Test Split and Cross-Validation


The dataset is divided into training and testing subsets using an 80:20 split. The training data are used to build the
model, while the test data provide an independent evaluation of predictive performance. Five-fold cross-validation is
configured during model training to provide a more robust estimate of model behavior and reduce dependence on a
single training split.

6. Predictive Model
A logistic regression classifier is developed because the target variable, survival, contains two possible outcomes:
survived and did not survive. The model uses passenger class, sex, age, family-related variables, fare, and
embarkation port as predictors. Logistic regression is suitable because it estimates the probability of belonging to the
survival class and produces interpretable coefficients.
7. Model Evaluation
The model is evaluated using a confusion matrix and classification performance measures. The confusion matrix
compares actual outcomes with predicted outcomes and provides information about correct and incorrect
classifications. Accuracy, sensitivity, specificity, and related measures can be used to assess performance. A ROC curve
is also generated, and the Area Under the Curve (AUC) is calculated to evaluate the model's ability to distinguish
between survival outcomes.

8. Model Interpretation
The model allows the effect of passenger characteristics on predicted survival probability to be examined. Variables
such as passenger class and sex are particularly useful because the Week 2 visual analysis showed differences in
survival rates across these groups. The model should not be interpreted as proof of causation; it identifies statistical
associations and predictive usefulness within this dataset.

9. Potential Improvements
Future improvements could include testing additional classification algorithms, tuning model parameters, applying
feature engineering, addressing class imbalance if necessary, comparing multiple cross-validation strategies, and
evaluating the model on additional datasets. More advanced models could be compared with logistic regression to
determine whether they improve predictive performance without sacrificing interpretability.

10. Conclusion
Week 3 extends the descriptive and visual analysis into formal statistical testing and predictive modeling. Hypothesis
tests and correlation analysis provide statistical evidence about relationships in the data, while logistic regression
provides a practical classification approach for predicting survival. The confusion matrix, ROC curve, and AUC offer
multiple perspectives on model performance. These results form the analytical foundation for the comprehensive
final report in Week 4.

11. R Code Used


# YuvaIntern - Virtual R Data Analyst Internship

# Week 3: Statistical Analysis and Predictive Modeling using R

# Project: Titanic Passenger Survival Analysis and Prediction Using R

library(tidyverse)

library(caret)

library(pROC)

[Link](123)

# 1. Load dataset
url <- "[Link]

titanic <- [Link](url, stringsAsFactors = FALSE)

# 2. Basic cleaning

titanic$age[[Link](titanic$age)] <- median(titanic$age, [Link] = TRUE)

get_mode <- function(x) {

ux <- unique(x[![Link](x) & x != ""])

ux[[Link](tabulate(match(x, ux)))]

titanic$embarked[[Link](titanic$embarked) | titanic$embarked == ""] <-

get_mode(titanic$embarked)

# Keep variables useful for prediction

model_data <- titanic %>%

select(survived, pclass, sex, age, sib_sp, parch, fare, embarked) %>%

mutate(

survived = factor(survived, levels = c(0, 1),

labels = c("No", "Yes")),

pclass = factor(pclass),

sex = factor(sex),

embarked = factor(embarked)

# 3. Hypothesis testing

# H0: Mean age is the same for survivors and non-survivors.

# H1: Mean age differs between survivors and non-survivors.

age_test <- [Link](age ~ survived, data = model_data)

print(age_test)

# Chi-square test: survival and sex

sex_test <- [Link](table(model_data$survived, model_data$sex))

print(sex_test)
# 4. Correlation among numerical variables

numeric_vars <- model_data %>%

select(age, sib_sp, parch, fare)

print(cor(numeric_vars, use = "[Link]"))

# 5. Train/test split

train_index <- createDataPartition(model_data$survived,

p = 0.80, list = FALSE)

train_data <- model_data[train_index, ]

test_data <- model_data[-train_index, ]

# 6. Cross-validation settings

ctrl <- trainControl(

method = "cv",

number = 5,

classProbs = TRUE,

savePredictions = "final"

# 7. Logistic regression model

logit_model <- train(

survived ~ pclass + sex + age + sib_sp + parch + fare + embarked,

data = train_data,

method = "glm",

family = binomial,

trControl = ctrl

print(logit_model)
# 8. Predictions

pred_class <- predict(logit_model, newdata = test_data)

pred_prob <- predict(logit_model, newdata = test_data, type = "prob")[, "Yes"]

# 9. Confusion matrix and performance

cm <- confusionMatrix(pred_class, test_data$survived,

positive = "Yes")

print(cm)

# 10. ROC and AUC

roc_obj <- roc(

response = test_data$survived,

predictor = pred_prob,

levels = c("No", "Yes"),

direction = "<"

print(auc(roc_obj))

plot(roc_obj, main = "ROC Curve - Titanic Survival Logistic Regression")

# 11. Model summary

print(summary(logit_model$finalModel))

# 12. Save model predictions

results <- test_data %>%

mutate(

predicted_survival = pred_class,

survival_probability = pred_prob

[Link](results, "titanic_week3_predictions.csv", [Link] = FALSE)


12. Screenshot Evidence to Insert Before Submission
 Hypothesis-test output for the age t-test.
 Chi-square test output for survival and sex.
 Correlation matrix output.
 Train/test split and cross-validation/model training output.
 Logistic regression model summary.
 Confusion matrix with performance metrics.
 ROC curve and AUC output.

You might also like