Description
Mayank Jaggi
Question 1
1.1
x=rnorm(25) #generating random numbers with std normal distribution
print(x) #vector with 25 elements
## [1] -0.6657578 0.7140872 -0.9789825 1.7858442 -0.9364864 1.0098515
## [7] 1.0833691 0.5140443 -1.0144362 -0.1557213 -1.5912311 -0.2918741
## [13] 1.5318438 1.0739362 0.4634867 0.3065718 0.8294984 1.5854654
## [19] -0.9137642 0.7390879 2.7108033 0.9854277 0.2501486 1.2468965
## [25] 0.5365554
1.2
1.2.1
Reshaping the vector into matrix
y1=matrix(x,nrow = 5,ncol = 5,byrow = TRUE) print(y1) #matrix by row
## [,1] [,2] [,3] [,4] [,5]
## [1,] -0.6657578 0.7140872 -0.9789825 1.7858442 -0.9364864
## [2,] 1.0098515 1.0833691 0.5140443 -1.0144362 -0.1557213
## [3,] -1.5912311 -0.2918741 1.5318438 1.0739362 0.4634867
## [4,] 0.3065718 0.8294984 1.5854654 -0.9137642 0.7390879
## [5,] 2.7108033 0.9854277 0.2501486 1.2468965 0.5365554
1.2.2
y2=matrix(x,nrow = 5,ncol = 5) print(y2) #matrix by column
## [,1] [,2] [,3] [,4] [,5]
## [1,] -0.6657578 1.0098515 -1.5912311 0.3065718 2.7108033
## [2,] 0.7140872 1.0833691 -0.2918741 0.8294984 0.9854277
## [3,] -0.9789825 0.5140443 1.5318438 1.5854654 0.2501486
## [4,] 1.7858442 -1.0144362 1.0739362 -0.9137642 1.2468965
## [5,] -0.9364864 -0.1557213 0.4634867 0.7390879 0.5365554
1.3
x2=rnorm(100) #generating random numbers
hist(x2,xlab =”Random Numbers”,ylab =”Frequency”, main =”Histogram for Random Numbers generated from Std Normal Distribution”)
Histogram for Random Numbers generated from Std Normal Distribution
Random Numbers
Question 2
library(ISLR) fix(Auto) names(Auto) #display different atrributes in Auto dataset
## [1] “mpg” “cylinders” “displacement” “horsepower”
## [5] “weight”
## [9] “name”
Question 3 “acceleration” “year” “origin”
attach(Auto)
pairs(~ mpg + displacement #attach concerned data frame
+ horsepower + weight + acceleration) #plotting pair of variables
Relation between variables:
1.mpg and displacement have a nonlinear negative correlation
2.mpg and horespower have a nonlinear negative correlation
3.mpg and weight have a linear positive correlation
4.mpg and acceleration have a no correlation
5.displacement and horsepower have a nonlinear positive correlation
6.displacement and weight have a linear positive correlation
7.displacement and accleration have a nolinear negative correlation
8.hoespower and weight have a linear positive correlation
9.horsepower and accleration have a nonlinear negative correlation
10.weight and acceleration have no correlation
Question 4
plot(horsepower,mpg,main=”Relation between mpg and horsepower”)
abline(lm(mpg~horsepower),col=”red”) #plot linear relation
Relation between mpg and horsepower
horsepower
# Question 5




Reviews
There are no reviews yet.