Friday, March 29, 2013

SESSION 10

ASSIGNMENT 1:

Create 3 vector x,y,z and choose any random value for them , ensuring they are of equal length, bind them together. Create different 3 dimensional plots for the same.

Solution:

> ranvec<- rnorm(20,40,60)
> ranvec
> x<-sample(ranvec,15)
> y<-sample(ranvec,15)
> z<-sample(ranvec,15)
> A<-cbind(x,y,z)
> plot3d(A)


>plot3d([,1:3],col=rainbow(1000))



>plot3d([,1:3],col=rainbow(1000), type='s')


>plot3d([,1:3],col=rainbow(1000), type='h')


>plot3d([,1:3],col=rainbow(1000), type='l')



ASSIGNMENT 2: Read the documentation of rnorm and pnorm choose 2 random variable and create 3 plots :
(a) X-Y
(b) X-Y|Z(Introducing a variable z and cbind it to z and y with diff categories)
(c) color code and draw the graph
(d) Smooth and best fit line


Data set creation for two random samples 

> x<-rnorm(1000,50,20)
> y<-norm(1000,25,10)
> z1<-sample(letters,10)
> z2<-sample(z1,1000, replace= TRUE)
> z <-as.factors(z2)
> z



>qplot(x,y)

>qplot(x,z)

>qplot(x,z,alpha=I(2/10))

>qplot(x,y,color=z)

>qplot(log(x),log(y),color=z)

>qplot(x,y,geom=c("path","smooth"))

>qplot(x,y,geom=c("point","smooth"))

>qplot(x,y,geom=c("boxplot","jitter"))








Saturday, March 23, 2013

SESSION-9

WOLFRAM ALPHA'S FACEBOOK REPORT delves into your profile and breaks down all your activity into easy to digest graphs. It's surprisingly comprehensive so data like time of interaction ,word ,maps .relationship status and network structure is all visualized for your convenience. It is really good at intelligently displaying charts in response to data queries without the need for any configuration.As we are talking about social networking site and our data, there is an inevitable privacy question.Wolfram Alpha requires you to be logged in to Facebook and the gathers information through Facebook API, respecting the privacy settings it runs into. Data is cached for 1 hour with personally identifiable deleted after 1 hour.




GETTING STARTED

GAIN INSIGHT ON YOURSELF AND YOUR SOCIAL NETWORK

Connect with Facebook, sign in for free, and get unique, personalized information and analysis on your social  data- computed by WOLFRAM ALPHA.



WHEN DO YOU USE FACEBOOK?

When are you most active? Uploading photos and videos? Posting links? Using apps?



WHAT DO YOU TALK ABOUT ON FACEBOOK?

The bigger the word, the more often it is used  in your conversation.


WHEN YOUR FRIENDS AT IN LIFE?

Do your friends' age reflect, what kind of relation ship they are in?


WHERE IN THE WORLD ARE YOUR FRIENDS?

Where do your friends live in? Where are their hometown? Who come from which countries ? What does your network look like on map? Who lives farthest from you and closest to you.


EXPLORE THE STRUCTURE OF YOUR FRIEND NETWORK ?

How your friends connect to your other friends?High light your graph by relationship status ,age, gender or Facebook activity.



CONCLUSION

WOLFRAM ALPHA PERSONAL ANALYTIC OF FACEBOOK , the world's first computational engine, uses its expert level knowledge and algorithms to answer questions, generate reports, and do analysis  across thousands of domains. And the newest domain in your own life and social as seen through your Facebook.



Friday, March 15, 2013

Session 8

PANEL DATA ANALYSIS .

Perform Panel Data Analysis of "Produc" data
 Answer:There are three types of models:
       (i)  Pooled affect model
       (ii) Fixed affect model
       (iii)Random affect model

We will be determining which model is the best by using functions:
       pFtest : for determining between fixed and pooled
       plmtest : for determining between pooled and random
       phtest: for determining between random and fixed

------------------------------------------------------------------------------------------------------------

Loading Data
> data("Produc", package= "plm")
> head(Produc)


(i)  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)

(ii) 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)

(iii)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 


> pFtest(fixed,pool)


Pooled vs Random

Null Hypothesis: Pooled Affect Model
Alternate Hypothesis: Random Affect Model

> plmtest(pool)


Random vs Fixed

Null Hypothesis: No Correlation . Random Affect Model
Alternate Hypothesis: Fixed Affect Model

> phtest(random,fixed)


Conclusion: 
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. 


Thursday, February 7, 2013

session 5

Assignment 1

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 the return.


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

>head(z)

>close<-z$Close

>close

>close.ts<-ts(close)

>close.ts<-ts(close,deltat=1/12)

>close.ts<-ts(close,deltat=1/252)

>z.diff<-diff(close.ts)

>z.diff

>Returns<-cbind(close.ts,z.diff,lag(close.ts,k=-1)

>Returns

>plot(Returns)

>Returns<-z.diff/lag(close.ts,k=-1)

>plot(Returns)





 Assignment 2 question


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

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

> y<-z[1:700,1:9]

> head(y) 

> sapply(y,mean)

> y$ed<-factor(y$ed)

> y.est<-glm(default~age+ed+employ+address+income+debtinc+creddebt+othdebt,data=y,family="binomial")

> summary(y.est)

> confint.default(y.est)

> y2<-with(y,data.frame(age=mean(age),employ=mean(employ),address=mean(address),income=mean(income),debtinc=mean(debtinc),creddebt=mean(creddebt),othdebt=mean(othdebt),ed=factor(1:4)))

> y2$prob<-predict(y.est,newdata=y2,type="response")

> head(y2)





Tuesday, January 22, 2013

Session 3

ASSIGNMENT 1
(a) Using milage-groove data, fit 'lm' and comment on the application of 'lm'
>>Plot residual vs independent
>>Standardized vs independent
>>qqplot and  qqline


As it is type 2 ,parabolic, we will not be able to do regression.

qqplot and qqline




(b) Using alpha-pluto.


As it is randomplot, thus we can have regression here.
 qqplot and qqline


residual value


ASSIGNMENT 2
Calculate P value


P value =0.687
as p value is more than 5%, we accept the null hypothesis .


Tuesday, January 15, 2013

Session 2

Session 2

(!) Create Matrix and combine two columns

Syntax
> z<-c(1:9)
> dim(z)<-c(3,3)
> z1<-c(4,6,7,8,2,3,0,1,9)
> dim(z1)<-c(3,3)
>x<-z[,3]
>y<-z1[,3]
>z3<-cbind(x,y)
>z3



2) Multiplication of two matrix

Syntax
>obj1<-z
>obj2<-z1
>obj1%*%obj2



3)Regression

Syntax
>z<-read.csv(file.choose(),header=T)
>high<-z[,3]
>low<-z[,2]
>reg1<-lm(high~open,data=z)
>reg1
>plot(reg1)
>residual(reg1)
>cbind(high,open)



4) To generate data for normal distribution and plot the graph

>z<-read.csv(file.choose(),header=T)
>z<-rnorm(150,0,1)
>y<-dnorm(z)
>plot(z,y)