0% found this document useful (0 votes)
12 views4 pages

Business Analytics with R: Data Analysis

The document outlines a step-by-step guide for performing descriptive analytics using R, including loading datasets, calculating measures of central tendency, variability, and distribution. It provides code snippets for computing mean, median, mode, variance, standard deviation, skewness, and kurtosis, along with visualizations such as histograms and boxplots. Additionally, it includes instructions for generating frequency tables and creating bar graphs and pie charts for categorical data.
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)
12 views4 pages

Business Analytics with R: Data Analysis

The document outlines a step-by-step guide for performing descriptive analytics using R, including loading datasets, calculating measures of central tendency, variability, and distribution. It provides code snippets for computing mean, median, mode, variance, standard deviation, skewness, and kurtosis, along with visualizations such as histograms and boxplots. Additionally, it includes instructions for generating frequency tables and creating bar graphs and pie charts for categorical data.
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

RMIT Classification: Trusted

ISYS3447|ISYS3448: Introduction to Business Analytics


Descriptive Analytics using R

Step 1: Load the Dataset and Required Libraries

# Load necessary libraries

# Load dataset (replace with actual dataset)

data <- [Link]("your_dataset.csv")

# View dataset structure

str(data)

Step 2: Measure of Location (Central Tendency)

# Select a numeric variable (e.g., Sales)

variable <- data$Sales

# Calculate central tendency

mean_value <- mean(variable, [Link] = TRUE)

median_value <- median(variable, [Link] = TRUE)

mode_value <- [Link](names(sort(table(variable), decreasing = TRUE)


[1]))

# Print results

cat("Mean:", mean_value, "\n")

cat("Median:", median_value, "\n")

cat("Mode:", mode_value, "\n")

Interpretation:

The mean represents the average sales value.

The median is useful when outliers are present.

The mode shows the most frequently occurring sales value.

1
RMIT Classification: Trusted

Step 3: Measure of Variability (Dispersion)

# Compute range, variance, standard deviation, and IQR

range_value <- range(variable, [Link] = TRUE)

variance_value <- var(variable, [Link] = TRUE)

sd_value <- sd(variable, [Link] = TRUE)

iqr_value <- IQR(variable, [Link] = TRUE)

# Print results

cat("Range:", range_value, "\n")

cat("Variance:", variance_value, "\n")

cat("Standard Deviation:", sd_value, "\n")

cat("Interquartile Range:", iqr_value, "\n")

Interpretation:

A high variance or standard deviation indicates greater variability in sales.

The IQR helps in understanding the middle 50% of sales data.

Step 4: Measure of Distribution (Skewness & Kurtosis)

# Compute skewness and kurtosis

skew_value <- skewness(variable, [Link] = TRUE)

kurtosis_value <- kurtosis(variable, [Link] = TRUE)

# Print results

cat("Skewness:", skew_value, "\n")

2
RMIT Classification: Trusted

cat("Kurtosis:", kurtosis_value, "\n")

# Visualization: Histogram and Boxplot

hist(variable, main = "Histogram of Sales", col = "blue", breaks = 30)

boxplot(variable, main = "Boxplot of Sales", col = "red", horizontal = TRUE)

Interpretation:

 Skewness > 0 means right-skewed (longer right tail).


 Skewness < 0 means left-skewed (longer left tail).
 Kurtosis > 3 indicates a sharp peak (leptokurtic), while <3 suggests a
flatter distribution (platykurtic).

Step 5: Measures of Distribution in RStudio (Without Packages)

Generate a Frequency Table

# Generate frequency table for a categorical variable (e.g., Gender)

table(data$Gender)

# Generate frequency table for a numerical variable (e.g., Age groups)

table(cut(data$Age, breaks = seq(0, 100, by = 10))) # Groups Age into 10-


year bins

Create a Bar Graph

# Create bar plot for a categorical variable (e.g., Gender)

barplot(table(data$Gender),

main = "Gender Distribution",

col = c("blue", "pink"),

xlab = "Gender",

ylab = "Count")

Create a Pie Chart

3
RMIT Classification: Trusted

gender_counts <- table(data$Gender)

pie(gender_counts,

main = "Gender Proportion",

col = c("blue", "pink"),

labels = paste(names(gender_counts), round(gender_counts /


sum(gender_counts) * 100, 1), "%"))

Create a Histogram

# Create histogram for a numerical variable (e.g., Age)

hist(data$Age,

main = "Age Distribution",

col = "lightblue",

xlab = "Age",

ylab = "Frequency",

breaks = 10) # Adjust number of bins if necessary

Create a Boxplot

# Create boxplot for Age

boxplot(data$Age,

main = "Boxplot of Age",

col = "orange",

horizontal = TRUE)

You might also like