Demo1

Data Set 1

Data Discription

Naturalgas is a panel data set from the “ARE” package, originating from 6 U.S. States from 1967-1989. The source of data is from Baltagi(2002).

It contains 138 observations on 10 variables.Variables includes: (a) state. It’s state abbreviation. (b) state code. (c) year. It denotes coding year. (d) consumption. It denotes consumption of natural gas by the residential sector. (e) Price. It denotes the price of natural gas. (f) eprice. It denotes the price of electricity. (g) oprice. It denotes the price of distillate fuel oil. (h) lprice. It denotes the price of liquefied petroleum gas. (i) heating. It denotes the heating degree days. (j) income. It denotes the real per-capita personal income.

People can use this dataset to analyze the factors affecting the price of natural gas.

Data Setting

library(AER)
Loading required package: car
Loading required package: carData
Loading required package: lmtest
Loading required package: zoo

Attaching package: 'zoo'
The following objects are masked from 'package:base':

    as.Date, as.Date.numeric
Loading required package: sandwich
Loading required package: survival
library(foreign)
data("NaturalGas")
Panel <- NaturalGas

Table1 Data for the first ten rows

head(x = Panel, n = 10L)
   state statecode year consumption price eprice oprice lprice heating   income
1     NY        35 1967      313656  1.42   2.98   7.40   1.47    6262 10903.75
2     NY        35 1968      319282  1.38   2.91   7.77   1.42    6125 11370.02
3     NY        35 1969      331326  1.37   2.84   7.96   1.38    6040 11578.68
4     NY        35 1970      346533  1.40   2.87   8.33   1.37    6085 11586.77
5     NY        35 1971      352085  1.50   3.07   8.80   1.40    5907 11657.42
6     NY        35 1972      363412  1.62   3.26   8.85   1.50    6248 11860.80
7     NY        35 1973      342608  1.74   3.51  10.08   1.62    5450 11943.15
8     NY        35 1974      341032  2.00   4.66  15.49   1.74    5858 11951.04
9     NY        35 1975      327384  2.54   5.13  16.37   2.00    5583 11653.49
10    NY        35 1976      339949  2.87   5.37  17.30   2.54    6238 11689.96

Table2 Stucture of panel data

table(Panel$year, Panel$state)
      
       CA FL MI NY TX UT
  1967  1  1  1  1  1  1
  1968  1  1  1  1  1  1
  1969  1  1  1  1  1  1
  1970  1  1  1  1  1  1
  1971  1  1  1  1  1  1
  1972  1  1  1  1  1  1
  1973  1  1  1  1  1  1
  1974  1  1  1  1  1  1
  1975  1  1  1  1  1  1
  1976  1  1  1  1  1  1
  1977  1  1  1  1  1  1
  1978  1  1  1  1  1  1
  1979  1  1  1  1  1  1
  1980  1  1  1  1  1  1
  1981  1  1  1  1  1  1
  1982  1  1  1  1  1  1
  1983  1  1  1  1  1  1
  1984  1  1  1  1  1  1
  1985  1  1  1  1  1  1
  1986  1  1  1  1  1  1
  1987  1  1  1  1  1  1
  1988  1  1  1  1  1  1
  1989  1  1  1  1  1  1

Table3 Summary Table

summary(Panel)
 state   statecode      year      consumption         price      
 CA:23   5 :23     1967   :  6   Min.   :  9430   Min.   :0.680  
 FL:23   10:23     1968   :  6   1st Qu.: 49104   1st Qu.:1.380  
 MI:23   23:23     1969   :  6   Median :300836   Median :2.775  
 NY:23   35:23     1970   :  6   Mean   :252902   Mean   :3.422  
 TX:23   44:23     1971   :  6   3rd Qu.:346429   3rd Qu.:5.310  
 UT:23   45:23     1972   :  6   Max.   :637289   Max.   :8.060  
                   (Other):102                                   
     eprice           oprice          lprice         heating    
 Min.   : 1.980   Min.   : 5.01   Min.   :0.680   Min.   : 481  
 1st Qu.: 2.433   1st Qu.: 8.24   1st Qu.:1.258   1st Qu.:2082  
 Median : 4.520   Median :19.86   Median :2.615   Median :4272  
 Mean   : 5.054   Mean   :24.64   Mean   :3.208   Mean   :4155  
 3rd Qu.: 7.282   3rd Qu.:40.10   3rd Qu.:5.192   3rd Qu.:6498  
 Max.   :10.860   Max.   :51.73   Max.   :7.870   Max.   :7440  
                                                                
     income     
 Min.   : 7465  
 1st Qu.: 9637  
 Median :11367  
 Mean   :11193  
 3rd Qu.:12125  
 Max.   :16425  
                

Coplot

coplot(data     =  Panel,
       formula  = price ~ year | state)

The price of Natural Gas from 1967 to 1989 in 6 states

 library(ggplot2)
 ggplot(Panel, aes(x=year,y= price,color= state))+
  geom_point()

Energy Price between 1967-1989

library(ggplot2)
library(reshape2)
long_data <- melt(NaturalGas, id.vars = "year", measure.vars = c("oprice", "price", "lprice", "eprice"))
ggplot(long_data, aes(x = year, y = value, color = variable)) +
  geom_line() +
  labs(
    title = "Energy Prices between 1967-1989",
    x = "year",
    y = "Price",
    color = "Price Type"
  ) +
  theme_minimal()

##Data Set2

###Data Discription Survey is a Cross Sectional data frame contains the responses of 237 Statistics I students at the University of Adelaide to a number of questions from the “MASS” package.

It contains 237 observations on 12 variables.Variables includes: (a) Sex. It denotes the sex of the student. (b) Wr.Hnd. It denotes span (distance from tip of thumb to tip of little finger of spread hand) of writing hand, in centimetres. (c) W.Hnd. It denotes the writing hand of student. (d) Fold. It denotes fold your arms! (e) Pulse. It denotes the pulse rate of student. (f) Clap. It denotes the top hands when you clap. (g) Exer. It denotes the frequency of student exercises. (h) Smoke. It denotes the frequency of smoking. (i) Height. It denotes height of the student in centimetres. (j) M.I. whether the student expressed height in imperial (feet/inches) or metric (centimetres/metres) units. (Factor, levels “Metric”, “Imperial”.) (k) Age. It denotes the age of student in year.

People can use this dataset to analyze the habits of these students.

Data Setting

library(MASS)
data("survey")

Table1 Data for the first and last ten rows

head(x = survey, n = 10L)
      Sex Wr.Hnd NW.Hnd W.Hnd    Fold Pulse    Clap Exer Smoke Height      M.I
1  Female   18.5   18.0 Right  R on L    92    Left Some Never 173.00   Metric
2    Male   19.5   20.5  Left  R on L   104    Left None Regul 177.80 Imperial
3    Male   18.0   13.3 Right  L on R    87 Neither None Occas     NA     <NA>
4    Male   18.8   18.9 Right  R on L    NA Neither None Never 160.00   Metric
5    Male   20.0   20.0 Right Neither    35   Right Some Never 165.00   Metric
6  Female   18.0   17.7 Right  L on R    64   Right Some Never 172.72 Imperial
7    Male   17.7   17.7 Right  L on R    83   Right Freq Never 182.88 Imperial
8  Female   17.0   17.3 Right  R on L    74   Right Freq Never 157.00   Metric
9    Male   20.0   19.5 Right  R on L    72   Right Some Never 175.00   Metric
10   Male   18.5   18.5 Right  R on L    90   Right Some Never 167.00   Metric
      Age
1  18.250
2  17.583
3  16.917
4  20.333
5  23.667
6  21.000
7  18.833
8  35.833
9  19.000
10 22.333
tail(x = survey, n = 10L)
       Sex Wr.Hnd NW.Hnd W.Hnd   Fold Pulse  Clap Exer Smoke Height      M.I
228   Male   20.0   19.8 Right L on R    68 Right Freq Never 185.00   Metric
229 Female   18.6   18.8 Right L on R    70 Right Freq Regul 167.00   Metric
230   Male   18.6   19.6 Right L on R    71 Right Freq Occas 185.00   Metric
231 Female   18.8   18.5 Right R on L    80 Right Some Never 169.00   Metric
232   Male   18.0   16.0 Right R on L    NA Right Some Never 180.34 Imperial
233 Female   18.0   18.0 Right L on R    85 Right Some Never 165.10 Imperial
234 Female   18.5   18.0 Right L on R    88 Right Some Never 160.00   Metric
235 Female   17.5   16.5 Right R on L    NA Right Some Never 170.00   Metric
236   Male   21.0   21.5 Right R on L    90 Right Some Never 183.00   Metric
237 Female   17.6   17.3 Right R on L    85 Right Freq Never 168.50   Metric
       Age
228 17.417
229 20.333
230 19.333
231 18.167
232 20.750
233 17.667
234 16.917
235 18.583
236 17.167
237 17.750

###Table2 Scatter plot of Age and Height

 library(ggplot2)
 ggplot(survey, aes(x=Age,y= Height,color= Sex))+
  geom_point()
Warning: Removed 28 rows containing missing values or values outside the scale range
(`geom_point()`).

Table1 Data for the first and last ten rows

table(survey$Smoke, survey$Age)
       
        16.75 16.917 17 17.083 17.167 17.25 17.333 17.417 17.5 17.583 17.667
  Heavy     0      0  0      0      1     0      0      0    0      0      1
  Never     1      2  1      5     10     6      3      9   12      3      5
  Occas     0      1  1      2      0     0      0      0    1      0      0
  Regul     0      0  0      0      0     0      0      0    0      1      0
       
        17.75 17.833 17.917 18 18.083 18.167 18.25 18.333 18.417 18.5 18.583
  Heavy     0      1      0  0      0      0     0      0      1    0      0
  Never     4      1      4  4      2      7     4      4      2    6      5
  Occas     0      0      0  1      0      0     1      0      2    1      0
  Regul     2      0      1  0      1      0     0      0      0    1      0
       
        18.667 18.75 18.833 18.917 19 19.083 19.167 19.25 19.333 19.417 19.5
  Heavy      0     0      0      1  0      0      0     0      0      0    0
  Never      3     5      1      4  4      2      3     2      3      1    1
  Occas      1     0      0      1  0      0      1     1      1      0    0
  Regul      1     0      0      1  0      0      1     1      0      1    0
       
        19.667 19.75 19.833 19.917 20 20.083 20.167 20.333 20.417 20.5 20.667
  Heavy      0     0      0      0  0      1      0      0      0    0      1
  Never      3     1      2      3  2      1      4      3      1    1      0
  Occas      0     0      0      1  0      0      0      0      0    0      0
  Regul      0     0      0      0  1      0      0      1      0    0      0
       
        20.75 20.833 20.917 21 21.083 21.167 21.25 21.333 21.417 21.5 21.583
  Heavy     0      0      1  0      1      0     0      0      0    0      0
  Never     2      1      0  2      1      3     1      1      1    1      1
  Occas     0      0      0  0      0      0     0      0      0    0      0
  Regul     0      0      0  0      0      0     0      0      0    0      0
       
        21.917 22.333 22.833 22.917 23 23.083 23.25 23.417 23.5 23.583 23.667
  Heavy      0      0      1      0  0      0     0      0    0      0      0
  Never      1      1      0      1  0      1     1      0    0      2      1
  Occas      0      0      0      0  0      0     0      1    0      0      0
  Regul      0      0      0      0  1      0     0      0    1      0      0
       
        23.833 24.167 24.667 25.5 26.5 27.333 28.5 28.583 29.083 30.667 30.75
  Heavy      0      0      0    0    0      0    0      0      0      0     0
  Never      1      1      1    1    1      1    1      1      0      1     1
  Occas      0      0      0    0    0      0    0      0      1      0     0
  Regul      0      0      0    0    0      0    0      0      0      0     0
       
        32.667 32.75 35.5 35.833 36.583 39.75 41.583 43.833 44.25 70.417 73
  Heavy      0     0    0      0      0     1      0      0     0      0  0
  Never      1     0    1      1      0     0      0      1     1      1  1
  Occas      0     0    0      0      0     0      1      0     0      0  0
  Regul      0     1    0      0      1     0      0      0     0      0  0