Friday, 29 March 2013

Assignment#10

Problem 1:-
To create 3 vectors, x, y, z and choose any random values for them, ensuring they are of equal length,
T<- cbind(x,y,z)
Create 3 dimensional plot of the same (all 3 types)
Solution:-
Commands:-
> sample<-rnorm(50,25,6)
> x<-sample(sample,10)
> y<-sample(sample,10)
> z<-sample(sample,10)
> T<-cbind(x,y,z)
Screenshots:-
Image
> plot3d(T)
Image
plot3d(T,col=rainbow(1000))
Image
plot3d(T,col=rainbow(1000),type=’s')
Image


Problem 2:-
Read the documentation of rnorm and pnorm,
Create 2 random variables
Create 3 plots:
1. X-Y
2. X-Y|Z (introducing a variable z and cbind it to z and y with 5 diff categories) Hint: ?factor
3. Color code and draw the graph
4. Smooth and best fit line for the curve
Solution:-
Commands:-
> x<-rnorm(200,mean=5,sd=1)
> y<-rnorm(200,mean=3,sd=1)
> z1<-sample(letters,5)
> z2<-sample(z1,200,replace=TRUE)
> z<-as.factor(z2)
> t<-cbind(x,y,z)

Screenshots:-
Image
> qplot(x,y)
Image
> qplot(x,z,alpha=I(2/10))
Image
> qplot(x,z)

Image
> qplot(x,y,geom=c(“point”,”smooth”))
Image
> qplot(x,y,colour=z)
Image
> qplot(log(x),log(y),colour=z)
Image

Sunday, 24 March 2013

Assignment# 9

Assignment # 9
Node XL

NodeXL is a social network analysis and visualization software tool.It offers microsoft excel spreadsheet software.It allow us to import data from various social networking site such as twitter, facebook,youtube etc
Help us to group/cluster the imported data depending upon our requirements.
Network analysis help us to know people who are following us/a particular website,presence of key people in network group,relationships, details of people connecting with you or with theirs friends etc.
NodelXL has a modular architecture that allows for the up, analysis and visualize network data.
Set the color, shape, size, label, and opacity of individual vertices by filling in worksheet cells, or let NodeXL do it for you based on vertex attributes such as degree, betweenness centrality or PageRank.

                                                                Twitter



                                                                   Facebook


Friday, 15 March 2013

Assignment#8




Assignment 8 : Panel Data Analysis
Do Panel Data Analysis of "Produc" data analyzing  on three types of model :
      Pooled affect model
      Fixed affect model
      Random affect model

Determine which model is the best by using functions:
       pFtest : Fixed vs Pooled
       plmtest : Pooled vs Random
       phtest: Random vs Fixed
The data can be loaded using the following command
data(Produc , package ="plm")
head(Produc)











Pooled Affect Model

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 Affect Model:
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 Affect Model:
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)



Testing of Model
This can be done through Hypothesis testing between the models as follows:
H0: Null Hypothesis: the individual index and time based params are all zero
H1: Alternate Hypothesis: atleast one of the index and time based params is non zero
Pooled vs Fixed
Null Hypothesis: Pooled Affect Model
Alternate Hypothesis : Fixed Affect Model
Command:
> pFtest(fixed,pool)
Result:
data:  log(pcap) ~ log(hwy) + log(water) + log(util) + log(pc) + log(gsp) + log(emp) + log(unemp)
F = 56.6361, df1 = 47, df2 = 761, p-value < 2.2e-16
alternative hypothesis: significant effects
Since the p value is negligible so we reject the Null Hypothesis and hence Alternate hypothesis is accepted which is to accept Fixed Affect Model.
Pooled vs Random
Null Hypothesis: Pooled Affect Model
Alternate Hypothesis: Random Affect Model
Command :
> plmtest(pool)
Result:
  Lagrange Multiplier Test - (Honda)
data:  log(pcap) ~ log(hwy) + log(water) + log(util) + log(pc) + log(gsp) + log(emp) + log(unemp)
normal = 57.1686, p-value < 2.2e-16
alternative hypothesis: significant effects
Since the p value is negligible so we reject the Null Hypothesis and hence Alternate hypothesis is accepted which is to accept Random Affect Model.
Random vs Fixed
Null Hypothesis: No Correlation . Random Affect Model
Alternate Hypothesis: Fixed Affect Model
Command:
 > phtest(fixed,random)
Result:
 Hausman Test
data:  log(pcap) ~ log(hwy) + log(water) + log(util) + log(pc) + log(gsp) + log(emp) + log(unemp)
chisq = 93.546, df = 7, p-value < 2.2e-16
alternative hypothesis: one model is inconsistent
Since the p value is negligible so we reject the Null Hypothesis and hence Alternate hypothesis is accepted which is to accept Fixed Affect Model.
Conclusion: 
So after making all the tests we come to the conclusion that Fixed Affect Model is best suited to do the panel data analysis for "Produc" data set.
Hence , we conclude that within the same id i.e. within same "state" there is no variation.

Wednesday, 13 February 2013

Assignment# 6

Assignment 1: To find the historical volatility and log of returns data





Assignment 2: To create ACF plot of log returns and do Augmented Dickey-Fuller test























Thursday, 7 February 2013

Assignment # 5

Assignment-1
Download NSE data for a 6months period at least and show the returns, having selected the 10th data point as start and 95th as end.

Commands:-
> z<-read.csv(file.choose(),header=T)
> close<-z$Close
> close.ts<-ts(close)
> close.ts<-ts(close,deltat= 1/252)
> x<-ts(data=close.ts[10:95],frequency=1,deltat=1/252)
> x.ts<-ts(x)
> x.diff<-diff(x)
> y<-lag(x.ts,K=-1)
> Returns<-x.diff/y
> plot(Returns,main=" Returns from 10th to 95th day of NSE Mid-cap Index ")
> z1<-cbind(x.ts,x.diff,Returns)
> plot(z1,main=" Data from 10th to 95th day ; Difference ; Returns")

 

 

Assignment#2. 

1-700 data is available. Predict the data from 701-850, use the GLM estimation using LOGIT Analysis for the same.

 Commands  

> logit.eg<- read.csv(file.choose(), header=T)
> z1<-logit.eg[1:700,1:9]
> head(z1)
> z1$ed<-factor(z1$ed)
> z1.est<-glm(default ~ age + ed + employ + address + income, data=z1, family ="binomial")
> summary(z1.est)
> forecast<-logit.eg[701:850,1:8]
> forecast$ed<-factor(forecast$ed)
> forecast$probability<-predict(z1.est,newdata=forecast,type="response")
> head(forecast)
 
 
 
 
 

 
 

Wednesday, 23 January 2013

Business Application Lab-3

ASSIGNMENT 1(a):

Fit ‘lm’ and comment on the applicability of ‘lm’.

Plot1: Residual vs Independent curve.

Plot2: Standard Residual vs independent curve.
> file<-read.csv(file.choose(),header=T)
> file
  mileage groove
1       0 394.33
2       4 329.50
3       8 291.00
4      12 255.17
5      16 229.33
6      20 204.83
7      24 179.00
8      28 163.83
9      32 150.33
> x<-file$groove
> x
[1] 394.33 329.50 291.00 255.17 229.33 204.83 179.00 163.83 150.33
> y<-file$mileage
> y
[1]  0  4  8 12 16 20 24 28 32
> reg1<-lm(y~x)
> res<-resid(reg1)
> res
         1          2          3          4          5          6          7          8          9
 3.6502499 -0.8322206 -1.8696280 -2.5576878 -1.9386386 -1.1442614 -0.5239038  1.4912269  3.7248633
> plot(x,res)




Assignment 1 (b) -Alpha-Pluto Data


Fit ‘lm’ and comment on the applicability of ‘lm’.

Plot1: Residual vs Independent curve.

Plot2: Standard Residual vs independent curve.



Also do:

Qq plot
Qqline
> file<-read.csv(file.choose(),header=T)
> file
   alpha pluto
1  0.150    20
2  0.004     0
3  0.069    10
4  0.030     5
5  0.011     0
6  0.004     0
7  0.041     5
8  0.109    20
9  0.068    10
10 0.009     0
11 0.009     0
12 0.048    10
13 0.006     0
14 0.083    20
15 0.037     5
16 0.039     5
17 0.132    20
18 0.004     0
19 0.006     0
20 0.059    10
21 0.051    10
22 0.002     0
23 0.049     5
> x<-file$alpha
> y<-file$pluto
> x
 [1] 0.150 0.004 0.069 0.030 0.011 0.004 0.041 0.109 0.068 0.009 0.009 0.048
[13] 0.006 0.083 0.037 0.039 0.132 0.004 0.006 0.059 0.051 0.002 0.049
> y
 [1] 20  0 10  5  0  0  5 20 10  0  0 10  0 20  5  5 20  0  0 10 10  0  5
> reg1<-lm(y~x)
> res<-resid(reg1)
> res
         1          2          3          4          5          6          7
-4.2173758 -0.0643108 -0.8173877  0.6344584 -1.2223345 -0.0643108 -1.1852930
         8          9         10         11         12         13         14
 2.5653342 -0.6519557 -0.8914706 -0.8914706  2.6566833 -0.3951747  6.8665650
        15         16         17         18         19         20         21
-0.5235652 -0.8544291 -1.2396007 -0.0643108 -0.3951747  0.8369318  2.1603874
        22         23
 0.2665531 -2.5087486
> plot(x,res)



> qqnorm(res)
 > qqline(res)
 
Assignment 2: Justify Null Hypothesis using ANOVA

> file<-read.csv(file.choose(),header=T)
> file

   Chair Comfort.Level Chair1
1      I             2      a
2      I             3      a
3      I             5      a
4      I             3      a
5      I             2      a
6      I             3      a
7     II             5      b
8     II             4      b
9     II             5      b
10    II             4      b
11    II             1      b
12    II             3      b
13   III             3      c
14   III             4      c
15   III             4      c
16   III             5      c
17   III             1      c
18   III             2      c
> file.anova<-aov(file$Comfort.Level~file$Chair1)
> summary(file.anova)

            Df Sum Sq Mean Sq F value Pr(>F)
file$Chair1  2  1.444  0.7222   0.385  0.687

 P Value  = 0.687

Wednesday, 16 January 2013

BUSINESS APPLICATION LAB-2

Assignment -1
> z1<-c(12:20)
> dim(z1)<-c(3,3)
> z1
> z2<-c(11:19)
> dim(z2)<-c(3,3)
> z2
> x<-z1[,3]
> x
[1] 18 19 20
> y<-z2[,1]
> y
[1] 11 12 13
> z3<-cbind(x,y)
> z3



Assignment-2
Multiply matrix
> mul<-z1%*%z2
> mul

Assignment-3
Historical data of indices from NSE site from Dec 1 2012 to Dec 31 2012. Find Regression and Residuals.
> reg3<-lm(High~Open,data=nse2)
> reg3
Call:
lm(formula = High ~ Open, data = nse2)
Coefficients:
(Intercept) Open
1578.3358 0.7355
> high<-nse2[,3]
> open<-nse2[,2]
> reg3<-lm(high~open)
> reg3
Call:
lm(formula = high ~ open)
Coefficients:
(Intercept) open
1578.3358 0.7355

Assignment-4
Normal distribution data and plot it.
x=seq(70,130,length=200)
y=dnorm(x,mean=100,sd=10)
plot(x,y)