Friday, March 29, 2013

Assignment No 10

Assignment 10

Problem 1:-
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 and 
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

Friday, March 15, 2013

Assignment 8



Assignment - Panel Data Analysis

We will be doing Panel Data Analysis of "Produc" data

We will be analysing on three types of model :
      Pooled affect model
      Fixed affect model
      Random affect model

Then 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

> data(Produc , package ="plm")

> head(Produc)

    state year     pcap     hwy   water    util       pc   gsp    emp unemp
1 ALABAMA 1970 15032.67 7325.80 1655.68 6051.20 35793.80 28418 1010.5   4.7
2 ALABAMA 1971 15501.94 7525.94 1721.02 6254.98 37299.91 29375 1021.9   5.2
3 ALABAMA 1972 15972.41 7765.42 1764.75 6442.23 38670.30 31303 1072.3   4.7
4 ALABAMA 1973 16406.26 7907.66 1742.41 6756.19 40084.01 33430 1135.5   3.9
5 ALABAMA 1974 16762.67 8025.52 1734.85 7002.29 42057.31 33749 1169.8   5.5
6 ALABAMA 1975 17316.26 8158.23 1752.27 7405.76 43971.71 33604 1155.4   7.7

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

Oneway (individual) effect Pooling Model
Call:
plm(formula = log(pcap) ~ log(hwy) + log(water) + log(util) +
    log(pc) + log(gsp) + log(emp) + log(unemp), data = Produc,
    model = ("pooling"), index = c("state", "year"))

Balanced Panel: n=48, T=17, N=816

Residuals :
    Min.  1st Qu.   Median  3rd Qu.     Max.
-0.04950 -0.01940 -0.00412  0.01150  0.08690

Coefficients :
              Estimate Std. Error  t-value  Pr(>|t|)   
(Intercept)  0.7496721  0.0271054  27.6577 < 2.2e-16 ***
log(hwy)     0.5248704  0.0048326 108.6099 < 2.2e-16 ***
log(water)   0.1077579  0.0040454  26.6370 < 2.2e-16 ***
log(util)    0.4127255  0.0038337 107.6574 < 2.2e-16 ***
log(pc)     -0.0330829  0.0048219  -6.8610 1.361e-11 ***
log(gsp)     0.0758341  0.0108650   6.9797 6.170e-12 ***
log(emp)    -0.0891772  0.0076891 -11.5978 < 2.2e-16 ***
log(unemp)   0.0043878  0.0029465   1.4891    0.1368   
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Total Sum of Squares:    724.14
Residual Sum of Squares: 0.56734
R-Squared      :  0.99922
      Adj. R-Squared :  0.98942
F-statistic: 147217 on 7 and 808 DF, p-value: < 2.22e-16

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)
Oneway (individual) effect Within Model

Call:
plm(formula = log(pcap) ~ log(hwy) + log(water) + log(util) +
    log(pc) + log(gsp) + log(emp) + log(unemp), data = Produc,
    model = ("within"), index = c("state", "year"))

Balanced Panel: n=48, T=17, N=816

Residuals :
     Min.   1st Qu.    Median   3rd Qu.      Max.
-0.069800 -0.005280 -0.000327  0.005360  0.061200

Coefficients :
             Estimate Std. Error t-value  Pr(>|t|)   
log(hwy)    0.5418395  0.0109565 49.4536 < 2.2e-16 ***
log(water)  0.1215676  0.0053719 22.6304 < 2.2e-16 ***
log(util)   0.3909247  0.0065771 59.4368 < 2.2e-16 ***
log(pc)     0.0177190  0.0096372  1.8386 0.0663624 . 
log(gsp)    0.0568433  0.0126569  4.4911 8.184e-06 ***
log(emp)   -0.0851515  0.0146508 -5.8121 9.073e-09 ***
log(unemp) -0.0092135  0.0024988 -3.6872 0.0002429 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Total Sum of Squares:    9.4468
Residual Sum of Squares: 0.12613
R-Squared      :  0.98665
      Adj. R-Squared :  0.92015
F-statistic: 8033.41 on 7 and 761 DF, p-value: < 2.22e-16

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)
Oneway (individual) effect Random Effect Model
   (Swamy-Arora's transformation)
Call:
plm(formula = log(pcap) ~ log(hwy) + log(water) + log(util) +
    log(pc) + log(gsp) + log(emp) + log(unemp), data = Produc,
    model = ("random"), index = c("state", "year"))

Balanced Panel: n=48, T=17, N=816

Effects:
                    var   std.dev share
idiosyncratic 0.0001657 0.0128743 0.221
individual    0.0005848 0.0241825 0.779
theta:  0.8719 

Residuals :
    Min.  1st Qu.   Median  3rd Qu.     Max.
-0.06500 -0.00624 -0.00195  0.00454  0.06450

Coefficients :
              Estimate Std. Error t-value  Pr(>|t|)   
(Intercept)  0.6625006  0.0530786 12.4815 < 2.2e-16 ***
log(hwy)     0.5021294  0.0074551 67.3537 < 2.2e-16 ***
log(water)   0.1191683  0.0049801 23.9289 < 2.2e-16 ***
log(util)    0.3944635  0.0060802 64.8768 < 2.2e-16 ***
log(pc)      0.0101901  0.0075870  1.3431    0.1796   
log(gsp)     0.0599363  0.0122997  4.8730 1.323e-06 ***
log(emp)    -0.0767378  0.0125556 -6.1119 1.531e-09 ***
log(unemp)  -0.0034020  0.0022591 -1.5059    0.1325   
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Total Sum of Squares:    21.167
Residual Sum of Squares: 0.13965
R-Squared      :  0.9934
      Adj. R-Squared :  0.98366
F-statistic: 17380.4 on 7 and 808 DF, p-value: < 2.22e-16

Comparison:

The comparison between the models would be a Hypothesis testing based on the 
following concept: 
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)
       F test for individual effects
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
> plmtest(pool)
        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
> phtest(fixed,random)
        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 comparisons 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.

The Hindu RSS News

The Hindu - News http://www.thehindu.com/ RSS feed en-us Copyright 2013 The Hindu http://www.thehindu.com/news/international/world/gupta-ordered-to-pay-goldman-62-million/article4456124.ece http://www.thehindu.com/news/international/world/almaty-talks-start-high-on-hope/article4456109.ece http://www.thehindu.com/news/international/world/chuck-hagels-2011-antiindia-remarks-draw-ire/article4456098.ece http://www.thehindu.com/news/national/bansals-safe-budget/article4455805.ece http://www.thehindu.com/news/national/delhi-gangrape-case-dcp-summoned-on-plea-for-fir-against-transport-minister-officials/article4455792.ece http://www.thehindu.com/news/national/other-states/budget-ignores-northeast-says-cpi-m/article4455811.ece http://www.thehindu.com/news/national/tamil-nadu/dmk-delegation-meets-pm-on-cauvery/article4455806.ece http://www.thehindu.com/news/national/bill-to-curb-sexual-harassment-in-workplaces-passed-in-rajya-sabha/article4455795.ece http://www.thehindu.com/news/cities/bangalore/widows-murder-fast-track-court-awards-life-sentence-to-auto-driver/article4455645.ece http://www.thehindu.com/news/international/world/pope-to-be-called-emeritus-pope/article4455649.ece http://www.thehindu.com/news/national/kerala/railway-budget-a-humiliation-for-kerala-rajagopal/article4455664.ece http://www.thehindu.com/features/metroplus/society/smell-the-coffee/article4455306.ece http://www.thehindu.com/features/metroplus/cool-air-and-cold-silence/article4455642.ece http://www.thehindu.com/sci-tech/health/diet-and-nutrition/soak-up-some-sun/article4455404.ece http://www.thehindu.com/features/metroplus/Food/something-to-chew-on/article4455390.ece http://www.thehindu.com/features/friday-review/art/between-objects-and-life/article4455259.ece http://www.thehindu.com/features/friday-review/music/beat-street/article4455300.ece http://www.thehindu.com/features/friday-review/music/boom-shackalak/article4455600.ece http://www.thehindu.com/features/metroplus/an-interesting-mix/article4455586.ece http://www.thehindu.com/features/metroplus/society/milos-silver-lining/article4455364.ece http://www.thehindu.com/features/metroplus/this-is-where-ramanujan-was-born/article4455332.ece http://www.thehindu.com/news/cities/Hyderabad/akbaruddin-admitted-to-apollo-hospital/article4455556.ece http://www.thehindu.com/features/metroplus/compact-and-clutchless/article4455330.ece http://www.thehindu.com/features/metroplus/the-automatic-upgrade/article4455322.ece http://www.thehindu.com/business/markets/sensex-plunges-316-pts-to-3month-low-as-rail-budget-fails-to-cheer-market/article4455473.ece http://www.thehindu.com/life-and-style/persian-tales/article4455296.ece http://www.thehindu.com/news/cities/chennai/dirty-toilets-send-an-sms/article4455466.ece http://www.thehindu.com/news/national/hyderabad-blast-nia-seeks-custody-of-suspected-im-operatives/article4455465.ece http://www.thehindu.com/news/national/school-teacher-arrested-for-molesting-9-girls-in-maharashtra/article4455406.ece http://www.thehindu.com/news/national/kurien-has-never-been-an-accused-in-suryanelli-case-kamal-nath/article4455445.ece http://www.thehindu.com/features/metroplus/to-market-to-market/article4455419.ece http://www.thehindu.com/news/national/other-states/2-kids-run-over-by-train-in-mp-railway-employee-burnt-alive/article4455441.ece http://www.thehindu.com/news/cities/bangalore/police-robber-injured-in-shootout-in-varthur/article4455403.ece http://www.thehindu.com/business/Economy/realtors-brokerages-free-to-run-banks-if-they-meet-norms-rbi/article4455378.ece http://www.thehindu.com/news/national/tn-government-to-move-bill-to-regulate-sale-of-acid/article4455311.ece http://www.thehindu.com/news/national/eticketing-to-be-revamped-by-yearend/article4455348.ece http://www.thehindu.com/news/news-in-pictures/article4455303.ece http://www.thehindu.com/news/national/day-in-pictures/article4455241.ece http://www.thehindu.com/news/national/auction-of-cdma-spectrum-from-march-11/article4455223.ece http://www.thehindu.com/news/national/kerala/no-decision-taken-on-recording-complaint-against-kurien-govt/article4455193.ece http://www.thehindu.com/news/national/rail-budget-reformist-forwardlooking-manmohan/article4455187.ece http://www.thehindu.com/news/international/world/18-foreign-tourists-killed-in-egypt-balloon-crash/article4455090.ece http://www.thehindu.com/news/national/no-fresh-hike-in-railway-passenger-fares/article4455057.ece http://www.thehindu.com/news/cities/Visakhapatnam/call-to-bridge-importexport-gap-to-revive-economy/article4455052.ece http://www.thehindu.com/news/cities/Vijayawada/turn-adversity-into-advantage/article4455047.ece http://www.thehindu.com/news/cities/Mangalore/powers-of-karnataka-police-act-misused-activists/article4455040.ece http://www.thehindu.com/news/resources/railway-minister-pawan-kumar-bansals-budget-speech/article4454995.ece Railway Minister Pawan Kumar Bansal’s speech presenting the Railway Budget 2013-14 in the Lok... ]]> http://www.thehindu.com/news/national/railway-budget-201314-dynamic-fuel-adjustment-for-freight-rates/article4454956.ece
  • New wheel factory to be set up at Rae Bareli
  • Dynamic fuel adjustment component to be introduced on freight rates from April one, that will result in less than five per cent i... ]]>
  • http://www.thehindu.com/news/international/world/gaza-militants-fire-rocket-into-israel/article4454870.ece Israeli police say a rocket has been fired from the Gaza Strip into Israel. A police spokesman says there was damage to a road but no injuries. It’s the first such rocket from the Palest... ]]> http://www.thehindu.com/news/national/railway-budget-201314-67-express-26-passenger-trains-introduced/article4454710.ece http://www.thehindu.com/news/national/railway-budget-201314-freight-rates-for-moving-diesel-cooking-fuel-hiked/article4454722.ece http://www.thehindu.com/news/national/railway-budget-201314-fire-extinguishers-to-be-kept-in-guard-vans/article4454733.ece http://www.thehindu.com/news/cities/Tiruchirapalli/over-one-lakh-farmers-to-get-compensation-in-nagapattinam/article4454853.ece http://www.thehindu.com/news/cities/Coimbatore/brahmos-in-iaf-soon-sivathanu-pillai/article4454842.ece http://www.thehindu.com/news/national/railway-ministers-wife-wants-helpline-for-women-passengers/article4454827.ece http://www.thehindu.com/news/cities/Madurai/security-up-in-temple/article4454784.ece http://www.thehindu.com/news/cities/Madurai/lok-adalat-settles-disputes-to-the-tune-of-rs-15-crore/article4454770.ece http://www.thehindu.com/news/cities/Madurai/high-court-stays-case-against-sp/article4454780.ece http://www.thehindu.com/news/national/railway-budget-201314-highlights/article4454715.ece http://www.thehindu.com/news/cities/Madurai/dalit-advocates-forum-sees-foul-play-in-not-installing-name-board/article4454737.ece http://www.thehindu.com/sport/cricket/india-clinches-first-test-by-eight-wickets/article4454742.ece http://www.thehindu.com/news/cities/Madurai/exclusive-world-that-keeps-common-man-out/article4454732.ece http://www.thehindu.com/news/cities/Thiruvananthapuram/chandy-learn-from-freedom-fighters/article4454727.ece http://www.thehindu.com/news/cities/Thiruvananthapuram/rail-budget-state-does-not-have-high-expectations/article4452446.ece http://www.thehindu.com/news/cities/Thiruvananthapuram/master-plan-in-6-months/article4452805.ece http://www.thehindu.com/news/cities/Thiruvananthapuram/pipe-bursts-leave-city-dry/article4452806.ece http://www.thehindu.com/news/cities/Thiruvananthapuram/hearths-ready-city-on-a-pongala-high/article4454702.ece http://www.thehindu.com/news/cities/Delhi/police-sweat-over-unclaimed-bags/article4454691.ece http://www.thehindu.com/news/cities/Delhi/porters-hope-rail-budget-has-something-for-them-this-year/article4454688.ece http://www.thehindu.com/news/cities/Delhi/better-connectivity-for-metro-airport-express-line-sought/article4454671.ece http://www.thehindu.com/news/cities/Delhi/bleak-prospects/article4452410.ece http://www.thehindu.com/news/cities/Delhi/a-bare-perspective/article4452403.ece http://www.thehindu.com/news/cities/chennai/court-dismisses-companys-civil-revision-petitions/article4452867.ece http://www.thehindu.com/news/cities/chennai/waste-management-plant-in-kuthambakkam-soon/article4452870.ece http://www.thehindu.com/news/cities/chennai/assault-victim-dies-at-gh/article4452871.ece http://www.thehindu.com/news/cities/chennai/park-turns-den-for-criminal-elements-in-vyasarpadi/article4452894.ece http://www.thehindu.com/news/cities/Delhi/feeling-left-out/article4452412.ece http://www.thehindu.com/news/cities/chennai/3-dead-in-road-accident/article4452878.ece http://www.thehindu.com/news/cities/chennai/fish-are-no-more-friendly-food/article4452884.ece http://www.thehindu.com/news/international/world/antiausterity-vote-delivers-hung-parliament-in-italy/article4454640.ece http://www.thehindu.com/news/cities/Kochi/recording-indias-growth-story/article4452763.ece http://www.thehindu.com/news/cities/Kochi/biennale-gets-taste-of-tales-in-a-cuppa/article4452914.ece http://www.thehindu.com/news/cities/Kochi/war-of-words-over-missing-apostrophe/article4452907.ece http://www.thehindu.com/news/cities/Kochi/city-roads-widen-trampling-upon-pedestrian-rights/article4452910.ece http://www.thehindu.com/news/cities/Kochi/ernakulam-pins-hopes-on-rail-budget/article4452912.ece http://www.thehindu.com/news/cities/Kochi/imtiaz-victim-of-gang-war-say-city-police/article4452908.ece http://www.thehindu.com/news/cities/Kochi/cmc-founder-principal-prescribes-government-support/article4452917.ece http://www.thehindu.com/news/cities/Kochi/kochi-medical-college-not-in-pink-of-health/article4452913.ece http://www.thehindu.com/news/national/karnataka/no-takers-for-auctioned-union-ministers-mps/article4452555.ece http://www.thehindu.com/news/national/karnataka/a-third-of-nominations-for-ulb-polls-is-from-independents/article4452407.ece http://www.thehindu.com/news/national/karnataka/bjp-confident-of-pulling-along-for-some-more-time/article4452550.ece http://www.thehindu.com/news/national/karnataka/shettar-may-not-opt-for-assembly-dissolution/article4452549.ece http://www.thehindu.com/news/national/karnataka/i-hope-nobody-goes-through-what-i-did/article4452920.ece http://www.thehindu.com/news/national/karnataka/governor-refuses-to-intervene/article4452377.ece http://www.thehindu.com/news/international/world/syrian-opposition-to-attend-rome-talks/article4454593.ece http://www.thehindu.com/news/cities/bangalore/the-good-news-is-that-most-young-runaways-are-traced/article4452929.ece http://www.thehindu.com/news/cities/bangalore/tracking-a-missing-child-is-a-challenging-task/article4452928.ece http://www.thehindu.com/news/cities/bangalore/yes-they-dream-of-going-home/article4452927.ece http://www.thehindu.com/news/cities/bangalore/gender-skew-in-missing-children-statistics-cause-for-worry/article4452922.ece http://www.thehindu.com/news/international/world/earthquake-shakes-haitian-capital/article4454577.ece http://www.thehindu.com/news/cities/bangalore/man-arrested-for-throwing-stones-at-ministers-car/article4452925.ece http://www.thehindu.com/news/cities/bangalore/yet-another-police-official-lands-in-lokayukta-net/article4452924.ece http://www.thehindu.com/news/cities/bangalore/union-accuses-turf-club-of-hiring-child-labour/article4452923.ece http://www.thehindu.com/news/cities/bangalore/russell-market-traders-observe-a-dark-anniversary/article4452921.ece http://www.thehindu.com/news/cities/bangalore/finally-ambedkar-statue-to-be-shifted/article4452811.ece http://www.thehindu.com/news/national/andhra-pradesh/blasts-nia-team-visits-nizamabad-bhainsa/article4453613.ece http://www.thehindu.com/news/national/andhra-pradesh/two-t-leaders-to-share-apcob-chief-post/article4453623.ece