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

Final Assignmnt Stat Kamii

The document generates plant growth data for three fertilizer types (A, B, C) and combines the data into a single data frame. It then performs a one-way ANOVA to compare the effect of fertilizer on plant growth, finding a significant effect. Finally, it creates a boxplot to visualize differences in plant growth between fertilizer types.

Uploaded by

kamranwaris405
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)
17 views6 pages

Final Assignmnt Stat Kamii

The document generates plant growth data for three fertilizer types (A, B, C) and combines the data into a single data frame. It then performs a one-way ANOVA to compare the effect of fertilizer on plant growth, finding a significant effect. Finally, it creates a boxplot to visualize differences in plant growth between fertilizer types.

Uploaded by

kamranwaris405
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
You are on page 1/ 6

Generating plant growth data for three fertilizer types

fertilizer_A <- c(12, 14, 16, 13, 15)

fertilizer_B<- c(10, 11, 9, 12, 10)

fertilizer_C<- c(15, 13, 14, 16, 15)

Combine the data into a single data frame

plant_data<- data.frame(Growth = c(fertilizer_A, fertilizer_B, fertilizer_C),Fertilizer =


rep(c("A", "B", "C"), each = 5))
print(plant_data)
Growth Fertilizer
Sr Growth Fertilizer
1 12 A
2 14 A
3 16 A
4 13 A
5 15 A
6 10 B
7 11 B
8 9 B
9 12 B
10 10 B
11 15 C
12 13 C
13 14 C
14 16 C
Perform one-way ANOVA
anova_result<- aov(Growth ~ Fertilizer, data = plant_data)
Print the summary of the ANOVA
summary(anova_result)
Df Sum Sq Mean Sq F value Pr(>F)
Fertilizer 2 51.6 25.8 15.18 0.000517 ***
Residuals 12 20.4 1.7
Signif. codes:
0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Load necessary libraries
library(ggplot2
Create a boxplot
ggplot(plant_data, aes(x = Fertilizer, y = Growth, fill = Fertilizer)) +geom_boxplot() + labs(title =
"Plant Gowth by Fertilizer Type",
x = "Fertilizer Type",
y = "Plant Growth") +theme_minimal()

# Create a data frame


fertilizer_data<- data.frame(A = fertilizer_A, B = fertilizer_B, C = fertilizer_C)

# Check the data


print(fertilizer_data)

# Calculate the correlation matrix


correlation_matrix =cor(fertilizer_data)

# Print the correlation matrix


print(correlation_matrix)

# Visualize the correlations with a pairs plot


Pairs(fertilizer_data, pch = 16col = "blue", main = "Scatterplot Matrix of Fertilizer Data")
QUIZ NO 4

library(psych)
cor.test(Iris[-5])
View(iris)
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
1 5.1 3.5 1.4 0.2 Setosa
2 4.9 3.0 1.4 0.2 Setosa
3 4.7 3.2 1.3 0.2 Setosa
4 4.6 3.1 1.5 0.2 Setosa
5 5.0 3.6 1.4 0.2 Setosa
6 5.4 3.9 1.7 0.4 Setosa
7 4.6 3.4 1.4 0.3 Setosa
8 6.4 3.2 4.5 1.5 Versicolor
9 6.9 3.1 4.9 1.5 Versicolor
10 5.5 2.3 4.0 1.3 Versicolor
11 6.5 2.8 4.6 1.5 Versicolor
12 5.7 2.8 4.5 1.3 Versicolor
13 6.3 3.3 4.7 1.6 Versicolor
14 5.8 2.7 5.1 1.9 Virginica
15 6.8 3.2 5.9 2.3 Virginica
16 6.7 3.3 5.7 2.5 Virginica
17 6.7 3.0 5.2 2.3 Virginica
18 6.3 2.5 5.0 1.9 Virginica

x<-corr.test(iris[-5])
print(iris-data)
# Calculate the correlation matrix
correlation_matrix<- cor(iris-data)

Call:corr.test(x = iris[-5])
Correlation matrix
Sepal.Length Sepal.Width Petal.Length Petal.Width
Sepal.Length 1.00 -0.12 0.87 0.82
Sepal.Width -0.12 1.00 -0.43 -0.37
Petal.Length 0.87 -0.43 1.00 0.96
Petal.Width 0.82 -0.37 0.96 1.00
Sample Size
[1] 150

Probability values (Entries above the diagonal are adjusted for multiple tests.)

Sepal.Length Sepal.Width Petal.Length Petal.Width

Sepal.Length 0.00 0.15 0 0


Sepal.Width 0.15 0.00 0 0
Petal.Length 0.00 0.00 0 0
Petal.Width 0.00 0.00 0 0

To see confidence intervals of the correlations, print with the short=FALSE option

# Print the correlation matrix


print(correlation_matrix)
# Install and load the 'corrplot' package
# install.packages("corrplot")
library(corrplot)
# Create a corrplot of the correlation matrix
corrplot(correlation_matrix, method = "color", col = colorRampPalette(c("blue", "white",
"red"))(50),
type = "upper", tl.col = "black", tl.srt = 45)
# Add a title
title("Correlation Corrplot of Iris Data"

Interpretation:
1. 1 indicates a perfect positive correlation.
2. -1 indicates a perfect negative correlation.
3. 0 indicates that there is no relationship between the different variables.

You might also like