Statistical Analysis and Data Display with R

Sarose Parajuli
2 min readFeb 23, 2023

--

Statistical Analysis and Data Display with R: Statistical analysis and data display are essential components of scientific research and decision-making. In this article, we will provide examples of statistical analysis and data display using the programming language R.

Statistical Analysis Examples:

Syntax:

t.test(x, y, alternative = c(“two.sided”, “less”, “greater”))

Example:

Let’s assume we have the following data:

Male Height: 68, 72, 74, 68, 71

Female Height: 62, 64, 67, 60, 65

We can perform a t-test using the following R code:

t.test(x = c(68, 72, 74, 68, 71), y = c(62, 64, 67, 60, 65))

The output will show us the t-value, degrees of freedom, and p-value.

Syntax:

anova(lm(dependent_variable ~ independent_variable, data = data))

Example:

Let’s assume we have the following data:

Breed 1: 25, 30, 27, 29, 32

Breed 2: 20, 22, 18, 21, 24

Breed 3: 30, 35, 32, 33, 36

We can perform ANOVA using the following R code:

anova(lm(weight ~ breed, data = data))

The output will show us the F-value, degrees of freedom, and p-value.

Data Display Examples:

Syntax:

boxplot(data, main = “Title of the plot”, xlab = “Label for x-axis”, ylab = “Label for y-axis”)

Example:

Let’s assume we have the following data:

Salaries: 45000, 55000, 70000, 60000, 80000, 100000, 90000

We can create a box plot using the following R code:

boxplot(salaries, main = “Distribution of Salaries”, xlab = “Company”, ylab = “Salary”)

The output will show us the median, quartiles, and outliers of the salary data.

Syntax:

plot(x, y, main = “Title of the plot”, xlab = “Label for x-axis”, ylab = “Label for y-axis”, col = “Color of the points”)

Example:

Let’s assume we have the following data:

Age: 20, 22, 24, 26, 28, 30

Height: 65, 67, 68, 70, 72, 73

We can create a scatter plot using the following R code:

plot(age, height, main = “Relationship between Age and height.

Learn more: Learn Data Visualization with R

Originally published at https://pyoflife.com on February 23, 2023.

--

--

Sarose Parajuli
Sarose Parajuli

Written by Sarose Parajuli

Passionate about Data Science and Machine Learning using R and python.

No responses yet