0% found this document useful (0 votes)
10 views

Assignment Statistical Analysis R

The assignment by Vaibhav Keshari focuses on statistical analysis using R with built-in datasets like mtcars and AirPassengers. It covers various operations including data exploration, regression, correlation, time series analysis, and data visualization using ggplot2. The conclusion emphasizes the effectiveness of R programming for data manipulation and analysis.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Assignment Statistical Analysis R

The assignment by Vaibhav Keshari focuses on statistical analysis using R with built-in datasets like mtcars and AirPassengers. It covers various operations including data exploration, regression, correlation, time series analysis, and data visualization using ggplot2. The conclusion emphasizes the effectiveness of R programming for data manipulation and analysis.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Assignment: Statistical Analysis R

Submitted By:
 Name: Vaibhav Keshari
 Roll Number: 1021
 Subject: Roman with R
 Course: B.A. Program

Table of Contents
1. Introduction
2. Data Exploration
3. Data Frame Operations
4. Vector Operations
5. Matrix and Array Operations
6. Correlation Analysis
7. Regression Analysis
8. Time Series Analysis
9. Pie Chart Visualization
10. Data Visualization with ggplot2
11. Export and Load Operations
12. Conclusion
1. Introduction
This assignment demonstrates statistical concepts and R
programming techniques using the built-in mtcars and
AirPassengers datasets. It includes operations on vectors,
matrices, arrays, regression, correlation, time series, and data
visualization.

2. Data Exploration
# Load the dataset and explore its structure
data("mtcars")
head(mtcars) # Display the first few rows
summary(mtcars) # Summary statistics
str(mtcars) # Structure of the dataset

3. Data Frame Operations


# Subset and modify data
mtcars_subset <- mtcars[, c("mpg", "hp", "wt")]
mtcars_subset$power_to_weight <- mtcars_subset$hp /
mtcars_subset$wt
high_mpg_cars <- subset(mtcars, mpg > 20)

4. Vector Operations
# Perform vector operations
car_weights <- mtcars$wt
squared_weights <- car_weights^2
mean_weight <- mean(car_weights)
sd_weight <- sd(car_weights)

5. Matrix and Array Operations


# Create a matrix and perform operations
car_matrix <- as.matrix(mtcars[1:3, 1:3])
transposed_matrix <- t(car_matrix)
car_array <- array(1:27, dim = c(3, 3, 3))

6. Correlation Analysis
# Compute and visualize correlations
cor_matrix <- cor(mtcars[, c("mpg", "hp", "wt")])
library(corrplot)
corrplot(cor_matrix, method = "circle")

7. Regression Analysis
# Perform and plot regression
regression_model <- lm(mpg ~ hp + wt, data = mtcars)
summary(regression_model)
plot(mtcars$wt, mtcars$mpg, main = "Regression Plot: MPG
vs Weight")
abline(lm(mpg ~ wt, data = mtcars), col = "red")
8. Time Series Analysis
# Analyze the AirPassengers dataset
data("AirPassengers")
plot(AirPassengers, main = "AirPassengers Time Series", col =
"blue")
ts_decomposition <- decompose(AirPassengers)
plot(ts_decomposition)

9. Pie Chart Visualization


# Create a pie chart
cyl_counts <- table(mtcars$cyl)
pie(cyl_counts, labels = names(cyl_counts), main = "Cylinder
Distribution")

10. Data Visualization with ggplot2


# Scatter plot and boxplot using ggplot2
library(ggplot2)
ggplot(mtcars, aes(x = hp, y = mpg, color = as.factor(cyl))) +
geom_point(size = 3) +
theme_minimal() +
labs(title = "Horsepower vs MPG", x = "Horsepower", y =
"MPG", color = "Cylinders")
ggplot(mtcars, aes(x = as.factor(cyl), y = mpg, fill =
as.factor(cyl))) +
geom_boxplot() +
labs(title = "MPG by Cylinders", x = "Cylinders", y = "MPG") +
theme_classic()

11. Export and Load Operations


# Save and load dataset
write.csv(mtcars_subset, "mtcars_subset.csv")
loaded_data <- read.csv("mtcars_subset.csv")
head(loaded_data)

12. Conclusion
This assignment demonstrates how R programming can be
used for statistical analysis, data manipulation, and
visualization. The built-in datasets, combined with powerful
libraries like ggplot2 and corrplot, provide a robust
environment for analyzing data efficiently.

You might also like