Friday, 15 March 2013

IT and Business Application lab : Assignment 8

 
 
Assignment 8 : Panel Data Analysis
 
Problem I: Do Panel Data Analysis of "Produc" data analyzing on three types of model :
  1. Pooled affect model
  2. Fixed affect model
  3. Random affect model
Problem II: Determine which model is the best by using functions:
  1. pFtest : Fixed vs Pooled
  2. plmtest : Pooled vs Random
  3. phtest: Random vs Fixed
  4.  
     
Solution:
 
To load the dataCommands:

> data("Produc" , package ="plm")
> head(Produc)  
 
 
Pooled Affects Model
Commands:


> pool <- plm(log(pcap)~ log(hwy) + log(water) + log(util) + log(pc) + log(gsp) + log(emp) + log(unemp) , data =Produc, model=("pooling"), index = c("state","year"))
> summary(pool)
 
 
 
Fixed Affects ModelCommands:

> fixed <- plm(log(pcap)~ log(hwy) + log(water) + log(util) + log(pc) + log(gsp) + log(emp) + log(unemp) , data =Produc, model=("within"), index = c("state","year"))
> summary(fixed)
 
 
Random Affects ModelCommands:

> random <- plm(log(pcap)~ log(hwy) + log(water) + log(util) + log(pc) + log(gsp) + log(emp) + log(unemp) , data =Produc, model=("random"), index = c("state","year"))
> summary(random)
 
 
 
Tests:
Pooled vs Fixed:

H0: Pooled Affects Model
H1: Fixed Affects Model
 
 
As the p-value is very small, we reject the null hypothesis and accept the alternate hypothesis.
=> Fixed affects model is accepted.

Pooled vs Random:
H0: Pooled Affects Model
H1: Random Affects Model

 
As the p-value is very small, we reject the null hypothesis and accept the alternate hypothesis.
=> Random affects model is accepted.

Random vs Fixed:
H0: Random Affects Model
H1: Fixed Affects Model 
 
 
As the p-value is very small, we reject the null hypothesis and accept the alternate hypothesis.
=> Fixed affects model is accepted.

Conclusion:
By conducting all the above tests, we come to a conclusion that Fixed Affects Model is the best to do the panel data analysis for "Produc".

Wednesday, 13 February 2013

IT and Business Application lab : Assignment 6



Problem 1


1) Create log of returns data (from 01.01.2012 to 01.01.2013) and calculate historical volatility

2) Create ACF plot for the log returns data ,perform adf test and interpret.
Commands:

> stockprice<-read.csv(file.choose(),header=T)
> head(stockprice)
> closingprice<-stockprice[,5]
> closingprice.ts<-ts(closingprice,frequency=252)
> returns<-(closingprice.ts-lag(closingprice.ts,k=-1))/lag(closingprice.ts,k=-1)
> z<-scale(returns)+10
> logreturns<-log(z)
> logreturns

> acf(logreturns)
 
 


From the above graph, we can see that the measurements lie with in the 95% confidence interval. Therefore, the time series is stationary.

> T=252^0.5
> historicalvolatility<-sd(logreturns)*T
> historicalvolatility
> adf.test(logreturns)

 

From the test results, we can see that p-value=0.01 (<0.05).
Therefore, we reject the null hypothesis and accept the alternate hypothesis which states that the time series is stationary.


 

 
 

 

Thursday, 7 February 2013

IT and Business Application lab : Assignment 5


Problem I:
1. Find returns of NSE data of greater than 6 months having selected the 10th data point as start and 95th data point as end.
2. Find plot of that return

Solutions:
Commands:

z<-read.csv(file.choose(),header=T)
head(z)
open<-z$Open[10:95]
open.ts<-ts(open,deltat=1/252)
open.ts
summary(open.ts)
z.diff<-diff(open.ts)
z.diff
returns<-cbind(open.ts,z.diff,lag(open.ts,k=-1))
returns
returns<-z.diff/lag(open.ts,k=-1)
returns
plot(returns)



Problem II
Do logit analysis for 700 data points and predict the probability for the next 150 data points.

Solutions:
Commands


z<-read.csv(file.choose(),header=T)
Readdata<-z[1:700,1:9]
Readdata$ed<-factor(Readdata$ed)
Readdata.est<-glm(default~age+ed+employ+address+income+debtinc+creddebt+othdebt,data=Readdata,family="binomial")
summary(Readdata.est)
Forecast<-z[701:850,1:8]
Forecast$ed<-factor(Forecast$ed)
Forecast$prob<-predict(Readdata.est,newdata=Forecast,type="response")
head(Forecast)



Tuesday, 22 January 2013

IT and Business Application lab : Assignment 3


Problem 1: Using Mileage-Groove data, fit 'lm' and 'comment on the applicability of 'lm'.
Solution:
Commands:
>test1<-read.csv(file.choose(),header=T)


> a<-test1$mileage
> b<-test1$groove
> reg1<- lm(a~b)
> reg1


> res_var<-resid(reg1)
> res_var


> plot(b,res_var)

> qqnorm(res_var)

>qqline(res_var)

Linear Regression is not applicable as can be seen from the graph

Problem 2:
a) Plot residual and standard residual of independent variable
Solution: 
Commands:
 > test2<-read.csv(file.choose(),header=T)

> a<-test2$Pluto
> b<-test2$alpha
> reg1<- lm(a~b)
> reg1


> res_var<-resid(reg1)
> sres<-rstandard(reg1)



B) Plot qqplot and add a qqline
Solution:
Commands:
> plot(b,res_var)
> qqnorm(res_var)


> qqline(res_var)

Problem 3: Justify null hypothesis using Anova
Solution:
Commands:
> anova1<-read.csv(file.choose(),header=T)
> anova2<-aov(anova1$Comfort_level~anova1$Chair)     

p value=0.687
Since p-value is greater than 5%, we can't reject the null hypothesis.
 











Tuesday, 15 January 2013

IT and Business Application lab : Assignment 2


Problem 1
a) Create two matrices
Solution:            
Command
> a<- c(1,2,3,4,5,6,7,8,9)
> b<- c(32,48,1,5,10,12,15,18,23)
> dim(a)<- c(3,3)
> dim(b)<- c(3,3)
> a
     [,1] [,2] [,3]
[1,]    1    4    7
[2,]    2    5    8
[3,]    3    6    9
> b
     [,1] [,2] [,3]
[1,]   32    5   15
[2,]   48   10   18
[3,]    1   12   23  
b) Select 3rd column from first matrix {a} and 1st column from second matrix {b}
Solution:
Command
> a1<-a[ ,3]
> a1
[1] 7 8 9
> b1<-b[ ,1]
> b1
[1] 32  48 1
c) Combine the two matrices
Solution:
Command
> combine<-cbind(a1,b1)
> combine
     a1 b1
[1,]  7 32
[2,]  8 48
[3,]  9 1

Problem 2: Find the product of two matrices
Solution:
Command
> multiple<- a%*%b
> multiple
     [,1] [,2] [,3]
[1,]  231  129  248
[2,]  312  156  304
[3,]  393  183  360

Problem 3: Find the regression using nifty data from 01 Dec 2012 to 31 Dec 2012 ?
Solution:
Command
> nifty<-read.csv(file.choose(),header=T)

> open<- nifty[ ,2]
> high<- nifty[ ,3]
> data<- cbind(open,high)
> reg1<-lm(high~open,data=nifty)
> reg1

Call:
lm(formula = high ~ open, data = nifty)

Coefficients:
(Intercept)        open
  1578.3358       0.7355


Problem 4: Generate and plot a normal distribution curve
Solution:
Command
> x<-seq(0,100)
> y<-dnorm(x,mean=50,sd=5)
> plot(x,y,type="l")

Tuesday, 8 January 2013

IT and Business Application lab : Assignment 1


Problem 1:
a) Create line plot of x, where x is a variable.
Solution:            
Command:          
> x<-c(1,2,3)
> plot(x,type="l")

b) Create histogram of NSE data extracted from 1st October 2012 to 4th January 2013.
Solution:            
Command:       
>z<-read.csv(file.choose(),header=T)
>zcol1<-z[ ,3]
> plot(zcol1,type="h")


Problem 2:
Plot both lines and points. Also name the plot, x axis and y axis
Command:
>plot(zcol1,type="b",main="NSEGraph",xlab="Time",ylab="nifty")


Problem 3:
Create scatter plot by selecting the low values.
Command:
> zcol4<- z[,4]
> plot(zcol1,zcol4)


Problem 4:
Find the volatility of data?