Professional Documents
Culture Documents
Module0 - Part2 - Intro To R Functions
Module0 - Part2 - Intro To R Functions
##Descriptives in R
##or use dropdown from import
library(readr)
SENSEX <- read_csv("E:/IIM Sambalpur/Term V/BAR/Data/Sensex.csv") #import csv data
##preprocessing of data
SENSEX<-SENSEX[,1:5] #selects column1 to 5
SENSEX<-SENSEX[-133:-134,] #deletes row133 & 134
SENSEX<-SENSEX[1:132,]
SENSEX<-SENSEX[-c(-133:-134),] #rejects everything else apart from row133&134
install.packages("Hmisc")
library(Hmisc)
describe(SENSEX$Close)
install.packages("pastecs")
library(pastecs)
stat.desc(SENSEX[,5])
install.packages("psych")
library(psych)
describe(SENSEX[,5])
TSL<-as.data.frame(tatasteel)
GVK<-as.data.frame(gvkpil)
# view(TSL)
##doubt??
##look for observation no.=247 say (against ??? trading days)
stock_prices<-matrix(unlist(stock_comb),247,4)
stock_comb[1] ##replace 1 with 2:4
##Plotting in R
# #simple histogram
# hist(TSL[,1]) #histogram of column1
# hist(GVK[,1])
# # Colored Histogram with Different Number of Bins
# hist(TSL$Close, breaks=4, col="red") #contains only 4 sets (2 consecutive sets of previous one
merged)
# hist(GVK$Close, breaks=6, col="yellow")
#simple histogram
hist(TSL[,1]) #histogram of column1
# Colored Histogram with Different Number of Bins
hist(TSL$Close, breaks=4, col="red") #contains only 4 sets (2 consecutive sets of previous one
merged)
hist(GVK[,1])
hist(GVK$Close, breaks=6, col="yellow")
## doubt how is it plotted for continuous data
x <- GVK$Open
#doubt??
##kernel plots
plot(density(x))
plot(density(GVK$Close))
#doubt??
##boxplot
boxplot(TSL)
boxplot(GVK$Close)
#doubt??
library(e1071)
skewness(stock_prices[,1])##= -0.4219908
skewness(stock_prices[,2])#=0.2083
skewness(stock_prices[,3])#=0.00599
skewness(stock_prices[,4])#=0.8538869
##compare skewness
skew_1<-(stock_prices[,1]-595.25129)^3
skew_11<-sum(skew_1)/247 ## = -351452.152699
skew_1f<-skew_11/(var(stock_prices[,1])^1.5)
##compare skewness
skew_2<-sum((stock_prices[,2]-12.85344)^3)/nrow(stock_prices)##=28.383
skew_3<-sum((stock_prices[,3]-153.7834)^3)/247##=99.01688
skew_4<-mean((stock_prices[,4]-2610.22835)^3)##=9366989.915
skew_2/var(stock_prices[,2])^1.5 ##=0.2083754
skew_3/var(stock_prices[,3])^1.5 ##=0.005992238
skew_4/var(stock_prices[,4])^1.5 ##=0.8538869
#####freeing up memory
# remove(SENSEX)
# remove(gvkpil)
# remove(GVK)
# remove(TSL)
# remove(h)
# remove(stock_comb)
# remove(stock_comb1)
# remove(stock_prices)
# remove(start)
# remove(end)
# remove(i)
# remove(x)
# remove(ticker)
# remove(tatasteel)
# remove(xfit)
# remove(yfit)
# remove(skew_1)
# remove(skew_11)
# remove(skew_1f)
# remove(skew_2)
# remove(skew_3)
# remove(skew_4)