Toc ch1
Toc ch1
Pca
data("iris")
head(iris)
summary(iris)
library()
mypr<-prcomp(iris[,-5],scale=T)
plot(iris$Sepal.Length,iris$Sepal.Width)
plot(scale(iris$Sepal.Length),scale(iris$Sepal.Width))
mypr
summary(mypr)
plot(mypr,type="l")
biplot(mypr,scale=0)
"extract pc scores"
str(mypr)
mypr$x
iris2<-cbind(iris,mypr$x[,1:2])
head(iris2)
cor(iris[,-5],iris2[,6:7])
"End of prog"
install.packages("pls")
library(pls)
names(iris)
pcmodel<-pcr(Sepal.Length~Species+Sepal.Width+Petal.Length+Petal.Width,ncomp=3,data=iris,scale=T)
iris$pred<-predict(pcmodel,iris,ncomp = 2)
head(iris)
2. "k-means clustering "
data("iris")
names(iris)
new_data<-subset(iris,select = c(-Species))
new_data
cl<-kmeans(new_data,3)
cl
function(k){kmeans(data, k )$tot.withinss})
wss
plot(1:15, wss,
install.packages("cluster")
library(cluster)
labels=2, lines=0)
cl$cluster
cl$centers
plot(clusters)
table(clusterCut, iris$Species)
table(clusterCut1, iris$Species)
plot(clusters)
4. //hypothesis//
dataf<-seq(1,20,by=1)
dataf
mean(dataf)
sd(dataf)
a<-t.test(dataf,alternative="two.sided",mu=10,conf.int=0.95)
5. //time series//
data("AirPassengers")
class(AirPassengers)
start(AirPassengers)
end(AirPassengers)
frequency(AirPassengers)
summary(AirPassengers)
plot(AirPassengers)
abline(reg=lm(AirPassengers~time(AirPassengers)))
cycle(AirPassengers)
plot(aggregate(AirPassengers,FUN=mean))
boxplot(AirPassengers~cycle(AirPassengers))
6. Linear regression
height<-c(102,117,105,141,135,115,138)
weight<-c(61,46,62,54,60,69,51)
student<-lm(weight~height)
student
predict (student,data.frame(height=119),interval="confidence)
plot(student)
7.
ftest<-read.csv(file.choose(),sep=",",header=T)
var.test(ftest$time_g1,ftest$time_g2,alternative = "two.sided")
data1<-read.csv(file.choose(),sep = ",",header = T)
names(data1)
summary(data1)
head(data1)
anv<-aov(formula = satindex~dept,data=data1)
summary(anv)
data2<-read.csv(file.choose(),sep=",",header = T)
names(data2)
summary(data2)
summary(anv1)
Practical No :
Aim: Implement regression in R
Code:
attach(mtcars)
plot(wt,mpg)
abline(lm(mpg~wt))
Output:
Practical No:
Aim:
Code
Histogram
hist(mtcars$mpg)
Output:
DotChart
Code:
dotchart(mtcars$mpg,labels = row.names(mtcars),cex = .7,
Output:
Barplot
Code
counts<-table(mtcars$gear)
output:
Code:
counts<-table(mtcars$gear)
output:
Code:
counts<-table(mtcars$vs,mtcars$gear)
legend= rownames(counts))
output: