Saturday, 30 March 2013

RLab_Session10


3D PLOTTING


Assignment 1:

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

Data Set Creation Commands and DataSet :



Plotting 3D plot:

Normal Plot:   plot3d(T[, 1:3])




Colour Plot: plot3d(T[, 1:3], col = rainbow(1000))


Color Plot of spheres:  plot3d(T[, 1:3], col = rainbow(1000), type = 's')



Assignment 2:

Choose 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)
3. Color code and draw the graph 
4. Smooth and best fit line for the curve


Data set creation for two random variables and then introducing third variable z




Plots:

>qplot(x,y)


>qplot(x,z)


Semi-transparent plot

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


Colour plot

> qplot(x,y, color=z)


Logarithmic colour plot

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


Best Fit and Smooth curve using "geom"

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

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



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





Saturday, 23 March 2013

ITBA lab Session # 9 - 19 March 2013

# this post is created as a solution for assignment for IT & Business Applications Lab, Spring Semester, VGSoM, IIT Kharagpur Class of 2014.


I am a marketing enthusiast and love to browse on social networking sites. Being in my first year, I am trying to build my resume as strong as possible to derive the best out of it and get into a good job. Since I am aiming a job in marketing, I need something innovative, not only in the contents of my resume but also, in the way I present it. I tried to find out some good open source software that can help me do it.

In my last session of ITBAL, to my luck, my Professor introduced me to one such software and gave me some knowledge on data visualization. 

First, let us know what data visualization is all about. 

Data visualization is the study of the visual representation of data, meaning "information that has been abstracted in some schematic form, including attributes or variables for the units of information".

According to Friedman (2008) the "main goal of data visualization is to communicate information clearly and effectively through graphical means.

It doesn't mean that data visualization needs to look boring to be functional or extremely sophisticated to look beautiful. To convey ideas effectively, both aesthetic form and functionality need to go hand in hand, providing insights into a rather sparse and complex data set by communicating its key-aspects in a more intuitive way. Yet designers often fail to achieve a balance between form and function, creating gorgeous data visualizations which fail to serve their main purpose — to communicate information".


The tool that I used for developing my resume implementing data visualization is visual.ly .


Tool Analysis :  Visual.ly: (http://visual.ly/)

About:

Visual.ly is a community platform for data visualization and infographics. It was founded by Stew Langille, Lee Sherman, Tal Siach, and Adam Breckler in 2011.

Visual.ly is structured as both as a showcase for infographics as well as a marketplace and community for publishers, designers, and researchers. The site allows users to search images through description, tags, and sources in a variety of categories, ranging from Education to Business or Politics.Users can publish infographics to their personal profile, which they can subsequently share through their social networks.

Visual.ly maintains a team of data analysts, journalists, and designers that create infographics and data visualizations using the Visual.ly tools. They are currently developing a tool that allows anyone to create and publish their own data visualizations.Through this tool, users will be able to gather information from databases and APIs in an automated service to produce an infographic. 

By tapping into Visually's vibrant community of more than 35,000 designers, Marketplace is able to match infographic commissioners – brands, companies, agencies – with designers, Once matched, commissioners have direct access to the designers working on their projects and can communicate and transact with them in Visually's Project Center. Through such unique features as the Project Timeline, commissioners always know where their project stands and can ensure that it stays on time and on budget.

Visually partners with the world's leading publications and brands, bringing  tools, community, and talented team to bear data visualization needs, wherever bespoke creation is needed.


Some points that I found were wonderful about this tool were:

  • UI is very user friendly
  • it is open source
  • numerous options regarding visual presentation of different types of data are available
  • the full tool is available online and it is not necessary to install any software on your PC
  • it is fast
  • the results are attractive and elegant
  • themes and options suiting everyone's style and taste are available.
  • once the visual presentation of data is ready, all possible options to retain and avail that data are available.
Here is the picture of my resume, hope you will like it.......




I was amazed to see how easily this tool created such an image for me to use.
I wanted to explore this tool further.

Since I have already mentioned above, I am an active user of Facebook, so, I decided to play with my profile as well. Just wanted to see what turned out. 

So, I used "Your Complex Facebook tale by Amstel", one of the many templates available on http://create.visual.ly/ . I was happy to see what turned out....






Friday, 15 March 2013

Session 8 - R Lab

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



 Pooled Model

Command:
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"))




 Fixed Model

Command:
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"))





Random Model

Command:
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"))


Pooled vs Fixed 

Null Hypothesis: Pooled Model
Alternate Hypothesis : Fixed Model



Pooled vs Random 

Null Hypothesis: Pooled Model
Alternate Hypothesis: Random Model

Since the p value is negligible so we reject the Null Hypothesis and hence Alternate hypothesis is accepted which is to accept Random Model is better than Pooled Model


Conclusion: 

So after making all the comparisons we come to the conclusion that Fixed 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

SESSION 6 - Business Application Lab

Question :  
(a) Create and plot the log of returns data for a 13 month period and interpret the stationarity.
(b) Calculate historical volatility of the same returns.
(c) Carry out adf test for returns and interpret the results.


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

         Date    Open    High     Low   Close Shares.Traded Turnover..Rs..Cr.
1 01-Dec-2011 1937.80 1973.40 1930.25 1945.50      91246016            791.90
2 02-Dec-2011 1947.90 1981.05 1936.55 1977.85      90348679            781.31
3 05-Dec-2011 1975.55 1986.40 1968.60 1975.85      88981133            691.75
4 07-Dec-2011 1978.10 2001.85 1973.50 1978.45      99171329            872.43
5 08-Dec-2011 1976.25 1976.25 1928.65 1934.50     104371626            820.01
6 09-Dec-2011 1920.80 1932.10 1901.90 1919.00      90902176            659.08

> closeprice<-z$Close
> closeprice.ts<-ts(closeprice, frequency=252)
> returns<-(closeprice.ts-lag(closeprice.ts,k=-1))/lag(closeprice.ts,k=-1)
> manipulate<-scale(returns)+10
> logreturns<-log(manipulate)
> logreturns
> acf(logreturns)




We can see from the graph that almost all the errors lie between the two dotted lines i.e. between 95% confidence interval. Thus, we can conclude that the time interval is stationary.


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

Warning message:
sd(<matrix>) is deprecated.
 Use apply(*, 2, sd) instead.

> historicalvolatility
[1] 1.620009

> adf.test(logreturns)

        Augmented Dickey-Fuller Test

data:  logreturns 
Dickey-Fuller = -5.2022, Lag order = 6, p-value = 0.01
alternative hypothesis: stationary 

Warning message:
In adf.test(logreturns) : p-value smaller than printed p-value


Since p value is less that 0.5, we cannot accept the null hypothesis and so can conclude with 95% confidence that the time series is stationary and further analysis can be done 


Thursday, 7 February 2013

Session 5 - Business Application Lab


ASSIGNMENT 1 :

Converting the data in the time series format and then calculating the returns from it.
(Data taken - NSE MIDCAP 50 from July 31st to Dec 31st, 2012)

COMMANDS:

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

 [1] 1994.30 1993.30 2006.55 1990.00 2002.30 2033.70 2042.00 2046.85 2054.05
[10] 2057.85 2033.65 2063.55 2116.10 2155.80 2134.05 2191.65 2198.40 2203.40
[19] 2210.90 2216.90 2252.45 2269.65 2286.75 2298.00 2275.55 2255.90 2271.65
[28] 2238.95 2287.35 2286.05 2287.05 2254.00 2251.40 2281.30 2258.20 2258.80
[37] 2239.60 2228.80 2199.00 2188.10 2162.00 2174.40 2207.10 2226.45 2208.50
[46] 2214.35 2238.80 2242.30 2219.80 2229.75 2233.80 2233.70 2200.05 2178.80
[55] 2152.10 2168.00 2176.80 2176.10 2195.60 2226.20 2248.25 2288.45 2315.55
[64] 2332.05 2343.85 2369.60 2360.10 2377.95 2350.85 2361.85 2323.15 2347.85
[73] 2363.65 2388.25 2391.65 2379.35 2325.35 2327.45 2345.10 2334.00 2357.25
[82] 2369.50

> Close.ts<-ts(Close)
> Close.ts<-ts(Close,deltat=1/252)
> z1<-ts(data=Close.ts[10:95],frequency=1,deltat=1/252)
> z1.ts<-ts(z1)
> z1.ts

Time Series:
Start = 1
End = 86
Frequency = 1
 [1] 2057.85 2033.65 2063.55 2116.10 2155.80 2134.05 2191.65 2198.40 2203.40
[10] 2210.90 2216.90 2252.45 2269.65 2286.75 2298.00 2275.55 2255.90 2271.65
[19] 2238.95 2287.35 2286.05 2287.05 2254.00 2251.40 2281.30 2258.20 2258.80
[28] 2239.60 2228.80 2199.00 2188.10 2162.00 2174.40 2207.10 2226.45 2208.50
[37] 2214.35 2238.80 2242.30 2219.80 2229.75 2233.80 2233.70 2200.05 2178.80
[46] 2152.10 2168.00 2176.80 2176.10 2195.60 2226.20 2248.25 2288.45 2315.55
[55] 2332.05 2343.85 2369.60 2360.10 2377.95 2350.85 2361.85 2323.15 2347.85
[64] 2363.65 2388.25 2391.65 2379.35 2325.35 2327.45 2345.10 2334.00 2357.25
[73] 2369.50      NA      NA      NA      NA      NA      NA      NA      NA
[82]      NA      NA      NA      NA      NA

> z1.diff<-diff(z1)
> z2<-lag(z1.ts,K=-1)
> Returns<-z1.diff/z2
> plot(Returns,main="10th to 95th day returns")
> z3<-cbind(z1.ts,z1.diff,Returns)
> plot(z3,main="Data from 10th to 95th day, Difference, Returns")









ASSIGNMENT 2 :

Do logit analysis for 700 data points and then predict for 150 data points.


COMMANDS:

> z<-read.csv(file.choose(),header=T)
> z1<-z[1:700,1:9]
> head(z1)

  age ed employ address income debtinc creddebt othdebt default
1  41  3     17      12    176     9.3    11.36    5.01       1
2  27  1     10       6     31    17.3     1.36    4.00       0
3  40  1     15      14     55     5.5     0.86    2.17       0
4  41  1     15      14    120     2.9     2.66    0.82       0
5  24  2      2       0     28    17.3     1.79    3.06       1
6  41  2      5       5     25    10.2     0.39    2.16       0

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

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

Call:
glm(formula = default ~ age + ed + employ + address + income +
    debtinc + creddebt + othdebt, family = "binomial", data = z1)

Deviance Residuals:
    Min       1Q   Median       3Q      Max
-2.4322  -0.6463  -0.2899   0.2807   3.0255

Coefficients:
             Estimate Std. Error z value Pr(>|z|)  
(Intercept) -1.589302   0.605324  -2.626  0.00865 **
age          0.035514   0.017588   2.019  0.04346 *
ed2          0.307623   0.251629   1.223  0.22151  
ed3          0.352448   0.339937   1.037  0.29983  
ed4         -0.085359   0.472938  -0.180  0.85677  
ed5          0.874942   1.293734   0.676  0.49886  
employ      -0.260737   0.033410  -7.804 5.99e-15 ***
address     -0.105426   0.023264  -4.532 5.85e-06 ***
income      -0.007855   0.007782  -1.009  0.31282  
debtinc      0.070551   0.030598   2.306  0.02113 *
creddebt     0.625177   0.112940   5.535 3.10e-08 ***
othdebt      0.053470   0.078464   0.681  0.49558  
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

(Dispersion parameter for binomial family taken to be 1)

    Null deviance: 804.36  on 699  degrees of freedom
Residual deviance: 549.56  on 688  degrees of freedom
AIC: 573.56

Number of Fisher Scoring iterations: 6

> forecast<-z[701:850,1:8]
> forecast$ed<-factor(forecast$ed)
> forecast$probability<-predict(z1.est, newdata=forecast, type="response")
> head(forecast)

    age ed employ address income debtinc creddebt othdebt probability
701  36  1     16      13     32    10.9     0.54    2.94  0.00783975
702  50  1      6      27     21    12.9     1.32    1.39  0.07044926
703  40  1      9       9     33    17.0     4.88    0.73  0.63780431
704  31  1      5       7     23     2.0     0.05    0.41  0.07471587
705  29  1      4       0     24     7.8     0.87    1.01  0.34464735
706  25  2      1       3     14     9.9     0.23    1.15  0.45584645




Tuesday, 22 January 2013

Session3 - Business Application Lab


ASSIGNMENT 1a:

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)

 As the plot is parabolic, so we will not be able to do regression.


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



Tuesday, 15 January 2013

Business Applications Lab - Assignment2

Question1 : Crete two (3,3) matrices, select two columns i.e one from each, bind them using the cbind function.


> z1<-c(19,10,15,100,32,56,28,29,91)
> dim(z1)<-c(3,3)
> z1

     [,1] [,2] [,3]
[1,]   19  100   28
[2,]   10   32   29
[3,]   15   56   91

> z2<-c(32,48,01,05,10,12,15,18,23)
> dim(z2)<-c(3,3)
> z2

     [,1] [,2] [,3]
[1,]   32    5   15
[2,]   48   10   18
[3,]    1   12   23

> x<-z1[,3]
> y<-z2[,1]
> z3<-cbind(x,y)
> z3
      x  y
[1,] 28 32
[2,] 29 48
[3,] 91  1


Question 2: Multiply matrix one and two

Matrix product:

> c<-z1%*%z2
> c

     [,1] [,2] [,3]
[1,] 5436 1431 2729
[2,] 1885  718 1393
[3,] 3259 1727 3326


Question 3: Conduct regression analysis with a data set.(NIFTY data for 30 days from Dec1, 2012 to 31Dec, 2012).

> file<-read.csv(file.choose(),header=T)
> file
          Date    Open    High     Low   Close Shares.Traded Turnover..Rs..Cr.
1  03-Dec-2012 2289.60 2318.45 2289.60 2315.55     221786151           1759.25
2  04-Dec-2012 2315.60 2339.05 2309.55 2332.05     224551900           1999.35
3  05-Dec-2012 2334.15 2356.45 2334.15 2343.85     219629641           1946.34
4  06-Dec-2012 2344.50 2372.60 2321.10 2369.60     268855325           2261.74
5  07-Dec-2012 2370.80 2389.15 2349.30 2360.10     241957780           2259.00
6  10-Dec-2012 2361.70 2380.10 2361.70 2377.95     186464425           1753.51
7  11-Dec-2012 2379.40 2396.65 2322.65 2350.85     230985012           2031.35
8  12-Dec-2012 2352.25 2372.40 2340.90 2361.85     206841389           2276.39
9  13-Dec-2012 2362.45 2378.05 2317.65 2323.15     185643436           1786.32
10 14-Dec-2012 2323.30 2350.50 2316.50 2347.85     170835163           1579.63
11 17-Dec-2012 2347.90 2366.90 2347.90 2363.65     154928478           1421.17
12 18-Dec-2012 2363.25 2390.30 2336.95 2388.25     235307767           2213.90
13 19-Dec-2012 2390.40 2404.95 2387.25 2391.65     204243540           1990.85
14 20-Dec-2012 2389.85 2393.40 2366.00 2379.35     205320093           2144.65
15 21-Dec-2012 2377.90 2377.90 2321.40 2325.35     191408422           1927.55
16 24-Dec-2012 2325.45 2338.95 2314.90 2327.45     133759632           1217.90
17 26-Dec-2012 2328.15 2352.80 2328.15 2345.10     133492652           1147.80
18 27-Dec-2012 2346.30 2358.45 2330.15 2334.00     295318340           2323.49
19 28-Dec-2012 2335.25 2359.30 2334.70 2357.25     132734158           1222.84
20 31-Dec-2012 2357.10 2374.85 2357.10 2369.50     125335527           1123.46

> reg1<-lm(High~open,data=file)
> reg1

lm(formula = High ~ open, data = file)
Coefficients:
(Intercept)         open 
 462.5541       0.8111 


> file<-read.csv(file.choose(),header=T)
> file
          Date    Open    High     Low   Close Shares.Traded Turnover..Rs..Cr.
1  01-Oct-2012 5704.75 5722.95 5694.00 5718.80     123138510           4798.17
2  03-Oct-2012 5727.70 5743.25 5715.80 5731.25     165037864           6654.02
3  04-Oct-2012 5751.55 5807.25 5751.35 5787.60     171404290           6954.74
4  05-Oct-2012 5815.00 5815.35 4888.20 5746.95     255569804          12995.80
5  08-Oct-2012 5751.85 5751.85 5666.20 5676.00     142319000           5853.56
6  09-Oct-2012 5708.15 5728.65 5677.90 5704.60     119300415           5047.01
7  10-Oct-2012 5671.15 5686.50 5647.05 5652.15     126294361           4564.39
8  11-Oct-2012 5663.50 5721.10 5636.95 5708.05     148283847           6542.71
9  12-Oct-2012 5681.70 5725.00 5659.35 5676.05     130076802           6475.30
10 15-Oct-2012 5674.25 5693.70 5651.05 5687.25      93693482           3962.97
11 16-Oct-2012 5705.60 5714.00 5635.60 5648.00     117415701           5043.30
12 17-Oct-2012 5681.10 5684.35 5633.90 5660.25     123974371           5259.46
13 18-Oct-2012 5675.30 5722.50 5650.55 5718.70     144097860           6264.78
14 19-Oct-2012 5703.30 5711.70 5660.00 5684.25     124262817           5410.95
15 22-Oct-2012 5667.60 5721.55 5658.05 5717.15     103372318           4994.75
16 23-Oct-2012 5715.65 5720.80 5681.45 5691.40      81501427           3803.50
17 25-Oct-2012 5688.80 5718.75 5685.70 5705.30     158343061           7359.34
18 26-Oct-2012 5683.55 5697.20 5641.75 5664.30     101663820           4718.97
19 29-Oct-2012 5665.20 5698.30 5645.10 5665.60      93555816           3953.86
20 30-Oct-2012 5656.35 5689.90 5589.90 5597.90     116678775           5550.86
21 31-Oct-2012 5596.75 5624.40 5583.05 5619.70     112075316           4918.55
22 01-Nov-2012 5609.85 5649.75 5601.95 5645.05     107393402           4633.11
23 02-Nov-2012 5696.35 5711.30 5682.55 5697.70     111162841           4924.33
24 05-Nov-2012 5693.05 5709.20 5679.50 5704.20      74829213           3236.08
25 06-Nov-2012 5694.10 5730.80 5693.65 5724.40     115018796           4677.92
26 07-Nov-2012 5718.60 5777.30 5711.40 5760.10     133740615           5242.18
27 08-Nov-2012 5709.00 5744.50 5693.95 5738.75     117590261           4883.90
28 09-Nov-2012 5731.10 5751.70 5677.75 5686.25      98763127           4833.64
29 12-Nov-2012 5688.45 5718.90 5665.75 5683.70      92702799           4082.62
30 13-Nov-2012 5689.70 5698.25 5660.35 5666.95      16516842            680.72
31 15-Nov-2012 5650.35 5651.65 5603.55 5631.00     133979470           5554.05
32 16-Nov-2012 5624.80 5650.15 5559.80 5574.05     121900570           4996.15
33 19-Nov-2012 5577.30 5592.75 5549.25 5571.40     106988015           4336.84
34 20-Nov-2012 5604.80 5613.70 5548.35 5571.55     107481297           4399.93
35 21-Nov-2012 5582.50 5620.20 5561.40 5614.80     105148728           4228.47
36 22-Nov-2012 5628.60 5643.35 5608.00 5627.75      94058612           3867.76
37 23-Nov-2012 5635.45 5637.75 5593.55 5626.60      85082220           3213.06
38 26-Nov-2012 5648.65 5649.20 5623.45 5635.90      79291426           3246.23
39 27-Nov-2012 5658.50 5733.20 5658.00 5727.45     134407735           5380.95
40 29-Nov-2012 5736.70 5833.50 5736.10 5825.00     207295475           9110.93
41 30-Nov-2012 5836.00 5885.25 5827.85 5879.85     257047977          10777.34
42 03-Dec-2012 5878.25 5899.15 5854.60 5870.95     113423350           4726.68
43 04-Dec-2012 5866.80 5894.95 5859.00 5889.25     131020191           4816.70
44 05-Dec-2012 5906.60 5917.80 5891.35 5900.50     139653957           5583.78
45 06-Dec-2012 5926.30 5942.55 5838.90 5930.90     140267080           5667.65
46 07-Dec-2012 5934.00 5949.85 5888.65 5907.40     127607078           5722.45
47 10-Dec-2012 5916.05 5919.95 5888.10 5908.90      95975757           4339.84
48 11-Dec-2012 5923.80 5965.15 5865.45 5898.80     137415161           6403.06
49 12-Dec-2012 5917.80 5924.60 5874.25 5888.00     132665649           6117.63
50 13-Dec-2012 5900.35 5907.45 5841.35 5851.50     136616335           5976.15
51 14-Dec-2012 5846.90 5886.10 5839.15 5879.60     115159830           5012.83
52 17-Dec-2012 5860.50 5886.05 5850.15 5857.90     109547002           4998.19
53 18-Dec-2012 5873.60 5905.80 5823.15 5896.80     148907334           6740.66
54 19-Dec-2012 5917.30 5939.40 5910.80 5929.60     149439204           6731.27
55 20-Dec-2012 5934.45 5937.60 5881.45 5916.40     123911218           5390.76
56 21-Dec-2012 5888.00 5888.00 5841.65 5847.70     141152911           5603.96
57 24-Dec-2012 5869.00 5871.90 5844.70 5855.75      85336999           3433.98
58 26-Dec-2012 5864.95 5917.30 5859.55 5905.60      83871326           3447.53
59 27-Dec-2012 5930.20 5930.80 5864.70 5870.10     139613235           5955.51
60 28-Dec-2012 5887.15 5915.75 5879.50 5908.35      89669021           3863.47
61 31-Dec-2012 5901.20 5919.00 5897.15 5905.10      64809641           3021.71
62 01-Jan-2013 5937.65 5963.90 5935.20 5950.85      77902745           3298.74
63 02-Jan-2013 5982.60 6006.05 5982.00 5993.25     116057389           4992.90
64 03-Jan-2013 6015.80 6017.00 5986.55 6009.50      99989933           4883.13
65 04-Jan-2013 6011.95 6020.75 5981.55 6016.15     113232990           5191.38

> open<-file[,2]
> High<-file[,3]
> Data<-cbind(open,High)
> Data
         open    High
 [1,] 5704.75 5722.95
 [2,] 5727.70 5743.25
 [3,] 5751.55 5807.25
 [4,] 5815.00 5815.35
 [5,] 5751.85 5751.85
 [6,] 5708.15 5728.65
 [7,] 5671.15 5686.50
 [8,] 5663.50 5721.10
 [9,] 5681.70 5725.00
[10,] 5674.25 5693.70
[11,] 5705.60 5714.00
[12,] 5681.10 5684.35
[13,] 5675.30 5722.50
[14,] 5703.30 5711.70
[15,] 5667.60 5721.55
[16,] 5715.65 5720.80
[17,] 5688.80 5718.75
[18,] 5683.55 5697.20
[19,] 5665.20 5698.30
[20,] 5656.35 5689.90
[21,] 5596.75 5624.40
[22,] 5609.85 5649.75
[23,] 5696.35 5711.30
[24,] 5693.05 5709.20
[25,] 5694.10 5730.80
[26,] 5718.60 5777.30
[27,] 5709.00 5744.50
[28,] 5731.10 5751.70
[29,] 5688.45 5718.90
[30,] 5689.70 5698.25
[31,] 5650.35 5651.65
[32,] 5624.80 5650.15
[33,] 5577.30 5592.75
[34,] 5604.80 5613.70
[35,] 5582.50 5620.20
[36,] 5628.60 5643.35
[37,] 5635.45 5637.75
[38,] 5648.65 5649.20
[39,] 5658.50 5733.20
[40,] 5736.70 5833.50
[41,] 5836.00 5885.25
[42,] 5878.25 5899.15
[43,] 5866.80 5894.95
[44,] 5906.60 5917.80
[45,] 5926.30 5942.55
[46,] 5934.00 5949.85
[47,] 5916.05 5919.95
[48,] 5923.80 5965.15
[49,] 5917.80 5924.60
[50,] 5900.35 5907.45
[51,] 5846.90 5886.10
[52,] 5860.50 5886.05
[53,] 5873.60 5905.80
[54,] 5917.30 5939.40
[55,] 5934.45 5937.60
[56,] 5888.00 5888.00
[57,] 5869.00 5871.90
[58,] 5864.95 5917.30
[59,] 5930.20 5930.80
[60,] 5887.15 5915.75
[61,] 5901.20 5919.00
[62,] 5937.65 5963.90
[63,] 5982.60 6006.05
[64,] 6015.80 6017.00
[65,] 6011.95 6020.75


> plot(Data)

Question 4: To generate data for normal distribution and plot the distribution curve


> values<-rnorm(200,0,1)
> pden<-dnorm(values)
> values
  [1] -1.212658503  1.144412737 -0.076257883 -1.662723801  1.014397349
  [6]  0.298085249  0.690832528  0.081220209 -2.174915108 -0.387846953
 [11]  0.634259291  1.598308445  0.727160263 -0.338272441 -0.284610211
 [16] -1.299069158  0.157470853  0.210125273 -0.264202880 -0.388464144
 [21]  0.193014621  0.292243457 -2.205503648  0.544266037  1.185574716
 [26] -1.339446499  0.075737603 -0.698760186  1.572288320  0.329020815
 [31]  0.276460499 -0.537984405  0.378401719  0.676361023 -0.155897623
 [36] -1.131778456  1.356299711  0.995041134 -0.910172040 -1.761406632
 [41] -1.865450544 -1.695708100 -1.478140090 -0.526595367  0.720444943
 [46] -0.666523516 -2.539917155  0.020598579  1.973118387 -0.132048748
 [51]  0.562226518  0.321094517  0.566336873 -0.251379174  0.542427053
 [56] -0.674245418  0.227679916  0.942326287 -0.758402969  0.248632960
 [61] -0.742442987 -1.110226541 -0.495990762  0.377567613 -0.555267552
 [66] -0.709519328  0.641299635  0.568955919 -1.986334551  0.379948522
 [71] -1.144519327  0.738001745 -0.560330495 -0.368725706  1.154819933
 [76]  0.766115934  0.992143437  0.014509939 -0.979219755  0.627271773
 [81]  1.323852755 -0.386161074 -1.430092347 -0.428465970  1.086108328
 [86]  1.230540751 -0.226346816  0.311076874 -0.519889259  0.053055329
 [91]  0.263290862  1.714817225 -2.032008280 -0.908068722 -0.695804818
 [96]  0.385143492  0.527130243  0.331767802 -0.001809055 -0.639069707
[101] -1.381294124  0.624865455  0.546161264 -0.435410173  0.066997403
[106]  1.575355950  0.913508254 -0.669485113 -0.205003776 -0.181824476
[111] -2.041402385  0.302366038 -1.840515652  0.251437557 -0.376584514
[116] -0.534131653 -0.183747664  0.558964468  0.362134949  0.778956820
[121] -1.182019533 -1.471734444 -0.472484362 -0.792582124  0.191165666
[126]  0.607273957 -0.557886473 -0.760747944 -1.659017754  0.666088442
[131] -0.626927113  0.451030164 -1.700966938 -1.491511562  0.574410897
[136] -2.269773313 -0.228327727  1.259212984 -0.180174079 -0.322380430
[141]  0.788689685 -0.046116542 -0.543367125  0.793947727 -0.722587411
[146]  1.459673351 -0.947418258  0.357986938  0.507150608 -0.123667094
[151] -0.164765208  1.256389987  1.262174755  0.127171044 -1.638733630
[156] -0.214731594  0.451175336 -0.161854380  0.543049150  0.259825973
[161] -0.029524774  1.457667773 -0.686271605 -0.798777698  0.545540771
[166]  0.868119095 -0.881679059 -0.365765007  0.610286050  0.976887711
[171]  1.251709083 -1.125444610  1.666270364  0.169143452  0.460544164
[176]  0.528854950 -2.094457589 -0.192393227  0.709266338  0.337996968
[181] -0.034281920  0.670046751 -0.212690045  0.609973855  1.309954043
[186]  1.235052210 -0.076415711  0.934172220 -2.645418561 -0.835514307
[191]  1.299051379 -0.409748535 -1.161706295 -0.097863317 -0.793991394
[196]  0.770426701 -0.798517339 -0.439704910 -0.464795232  1.283117423

> plot(values,pden)