Introduction and Topic Overview

Welcome! Today, we're going to explore the stats package available in R, a powerful tool created for advanced statistical computations. One of the major advantages of using a tool like the stats package is its ability to handle complex problems that require multiple calculations — a key feature in areas such as engineering, data science, or any field that heavily relies on data analysis. In this lesson, you'll familiarize yourself with numerous features in the stats package, which will serve as additional tools in your data analytics toolbox.

Generating Normally Distributed Random Numbers in R

In statistics, distribution functions play a vital role as they help us identify the probability of potential outcomes for a random event. For example, in a dice game, the distribution function can inform us about the chances of rolling a six. Because we need some data to explore the stats package, let's generate a meaningful data sample using the rnorm() function:

R
# Simulating temperature data for a year in a city
temp_data <- rnorm(n=365, mean=30, sd=10)

In this example, we generate a vector of 365 values, which are normally distributed with a mean of 30 and a standard deviation of 10.

Using Descriptive Statistics Functions in R

The stats package in R offers numerous statistical functions. However, for skewness and kurtosis, we'll need to use the e1071 package. Skewness measures the asymmetry of a probability distribution around its mean, while kurtosis gauges how prone a distribution is to outliers. For example, these metrics could help us understand unusual variations in a city's annual temperature data.

# load the e1071 package
library(e1071)

data <- rnorm(n=1000)

# Compute skewness - a measure of data asymmetry
data_skewness <- skewness(data)

# Compute kurtosis - a measure of data "tailedness" or outliers
data_kurtosis <- kurtosis(data)

print(paste("Skewness: ", data_skewness))
print(paste("Kurtosis: ", data_kurtosis))
Interpretation of Skewness

Please take a look at the picture below. This graph showcases the asymmetry in statistical distributions. A negative skewness (blue curve) indicates that the left tail is longer or fatter than the right side, showing more lower-valued data. Conversely, a positive skewness (red curve) indicates a distribution where the right tail is longer or fatter, representing more higher-valued data. Skewness helps us identify the shape and direction of the spread in our data.

Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal