getwd()
## [1] "C:/Users/Mohit gupta/Documents/r assignment"
setwd("C:/Users/Mohit gupta/Documents/r assignment")
Reading the datasets in R.
ob1<- read.csv(paste("Dataset 1.csv" , sep=''))
ob2<- read.csv(paste("Dataset2.csv" , sep=''))
visualizing the length and breadth of your datasets.
dim(ob1)
## [1] 63 19
dim(ob2)
## [1] 16 4
A descriptive statistics (min, max, median etc) of each variable.
library(psych)
describe(ob1)
## vars n mean sd median trimmed mad min
## Sector* 1 63 32.00 18.33 32.00 32.00 23.72 1.00
## X2000.01 2 63 37.76 112.23 4.03 14.60 5.97 0.00
## X2001.02 3 63 63.93 157.88 5.07 25.51 7.52 0.00
## X2002.03 4 63 42.93 86.61 11.01 18.97 16.32 0.00
## X2003.04 5 63 34.73 67.65 6.37 18.98 9.44 0.00
## X2004.05 6 63 51.09 101.93 9.09 26.20 13.39 0.00
## X2005.06 7 63 87.93 206.44 22.62 38.13 32.80 0.00
## X2006.07 8 63 198.28 686.78 25.82 53.52 38.28 0.00
## X2007.08 9 63 390.09 1026.25 58.82 166.18 85.32 0.00
## X2008.09 10 63 498.35 1134.65 84.88 209.15 124.29 0.00
## X2009.10 11 63 410.07 926.81 69.74 194.59 103.25 0.00
## X2010.11 12 63 339.41 627.14 58.07 188.81 85.84 0.00
## X2011.12 13 63 557.47 1031.47 129.36 303.19 186.36 0.00
## X2012.13 14 63 355.93 778.09 95.41 173.96 135.04 0.00
## X2013.14 15 63 385.70 658.43 113.78 247.91 167.89 0.00
## X2014.15 16 63 490.96 837.79 177.22 281.21 231.29 0.00
## X2015.16 17 63 634.94 1335.31 159.13 291.26 226.50 0.00
## sector.total 18 63 4579.57 8046.52 1451.28 2844.47 1989.15 4.06
## sector.growth 19 63 4541.81 8012.39 1451.28 2812.21 2019.14 4.06
## max range skew kurtosis se
## Sector* 63.00 62.00 0.00 -1.26 2.31
## X2000.01 832.07 832.07 5.77 37.07 14.14
## X2001.02 873.23 873.23 3.70 14.36 19.89
## X2002.03 419.96 419.96 2.76 7.00 10.91
## X2003.04 368.32 368.32 3.05 10.15 8.52
## X2004.05 527.90 527.90 2.99 9.44 12.84
## X2005.06 1359.97 1359.97 4.27 21.21 26.01
## X2006.07 4713.78 4713.78 5.27 29.24 86.53
## X2007.08 6986.17 6986.17 4.87 26.29 129.30
## X2008.09 6183.49 6183.49 3.43 11.97 142.95
## X2009.10 5466.13 5466.13 3.84 15.88 116.77
## X2010.11 3296.09 3296.09 2.65 7.58 79.01
## X2011.12 5215.98 5215.98 2.67 7.23 129.95
## X2012.13 4832.98 4832.98 3.97 17.71 98.03
## X2013.14 3982.89 3982.89 3.14 12.57 82.95
## X2014.15 4443.26 4443.26 2.76 7.97 105.55
## X2015.16 6889.46 6889.46 3.22 10.24 168.23
## sector.total 50792.42 50788.36 3.48 15.39 1013.77
## sector.growth 50721.04 50716.98 3.51 15.63 1009.47
describe(ob2)
## vars n mean sd median trimmed mad min
## years 1 16 2008.50 4.76 2008.50 2008.50 5.93 2001.00
## fdi 2 16 18032.05 13232.34 21903.33 17594.56 16834.98 2187.85
## inflation 3 16 6.80 3.33 6.09 6.54 3.47 2.23
## exchange.rate 4 16 104.90 4.73 103.88 104.70 2.97 97.68
## max range skew kurtosis se
## years 2016.00 15.00 0.00 -1.43 1.19
## fdi 40000.99 37813.14 0.05 -1.62 3308.09
## inflation 14.97 12.74 0.81 -0.07 0.83
## exchange.rate 114.91 17.23 0.69 -0.47 1.18
one-way contingency tables for the categorical variables
table1<- with(ob1, table(sector.total))
table1
## sector.total
## 4.06 5.12 7.98 27.74 37.79 67.28 75.32 77.7
## 1 1 1 1 1 1 1 1
## 109.62 141.24 147.45 164.9 178.27 188.51 337.16 346.03
## 1 1 1 1 1 1 1 1
## 434.01 499.76 537.63 564.8 581.49 589.05 710.98 744.72
## 1 1 1 1 1 1 1 1
## 772.03 837.94 931.04 1093.83 1097.13 1111.31 1256.08 1451.28
## 1 1 1 1 1 1 1 1
## 1636.01 1637.28 1844.32 1852.46 1977.51 2084.26 2216.08 2376.95
## 1 1 1 1 1 1 1 1
## 3068.09 3109.13 3356.59 3592.11 4064.58 4336.72 4397.92 4977.03
## 1 1 1 1 1 1 1 1
## 6675.76 6815.7 7956.74 8890.36 9227.33 9747.05 10476.15 11872.48
## 1 1 1 1 1 1 1 1
## 11900.29 13849.51 15064.6 18382.32 21017.78 24187.95 50792.42
## 1 1 1 1 1 1 1
table2<- with(ob2, table(fdi))
table2
## fdi
## 2187.85 2378.71 2704.32 3218.69 4027.69 5539.75 12491.76 21383.07
## 1 1 1 1 1 1 1 1
## 22423.59 24299.32 24575.4 25834.38 30930.47 31395.96 35120.78 40000.99
## 1 1 1 1 1 1 1 1
table3<- with(ob2, table(inflation))
table3
## inflation
## 2.23 3.2 3.72 3.78 5.16 5.51 5.57 5.86 6.32 6.49 6.53 9.13
## 1 1 1 1 1 1 1 1 1 1 1 1
## 9.47 9.7 11.17 14.97
## 1 1 1 1
table4<- with(ob2, table(exchange.rate))
table4
## exchange.rate
## 97.68 99.17 101.78 101.97 102.32 102.71 102.82 103.46 104.3 105.13
## 1 1 1 1 1 1 1 1 1 1
## 105.17 106.1 106.3 111.86 112.76 114.91
## 1 1 1 1 1 1
two-way contingency tables for the categorical variables
table5<- xtabs(~fdi+ inflation, data= ob2)
table5
## inflation
## fdi 2.23 3.2 3.72 3.78 5.16 5.51 5.57 5.86 6.32 6.49 6.53 9.13 9.47
## 2187.85 0 0 0 1 0 0 0 0 0 0 0 0 0
## 2378.71 0 0 0 0 1 0 0 0 0 0 0 0 0
## 2704.32 0 0 1 0 0 0 0 0 0 0 0 0 0
## 3218.69 0 0 0 0 0 0 1 0 0 0 0 0 0
## 4027.69 0 1 0 0 0 0 0 0 0 0 0 0 0
## 5539.75 0 0 0 0 0 0 0 0 0 0 1 0 0
## 12491.76 0 0 0 0 0 1 0 0 0 0 0 0 0
## 21383.07 0 0 0 0 0 0 0 0 0 1 0 0 0
## 22423.59 0 0 0 0 0 0 0 0 0 0 0 1 0
## 24299.32 0 0 0 0 0 0 0 1 0 0 0 0 0
## 24575.4 0 0 0 0 0 0 0 0 0 0 0 0 0
## 25834.38 0 0 0 0 0 0 0 0 0 0 0 0 1
## 30930.47 0 0 0 0 0 0 0 0 1 0 0 0 0
## 31395.96 0 0 0 0 0 0 0 0 0 0 0 0 0
## 35120.78 0 0 0 0 0 0 0 0 0 0 0 0 0
## 40000.99 1 0 0 0 0 0 0 0 0 0 0 0 0
## inflation
## fdi 9.7 11.17 14.97
## 2187.85 0 0 0
## 2378.71 0 0 0
## 2704.32 0 0 0
## 3218.69 0 0 0
## 4027.69 0 0 0
## 5539.75 0 0 0
## 12491.76 0 0 0
## 21383.07 0 0 0
## 22423.59 0 0 0
## 24299.32 0 0 0
## 24575.4 1 0 0
## 25834.38 0 0 0
## 30930.47 0 0 0
## 31395.96 0 0 1
## 35120.78 0 1 0
## 40000.99 0 0 0
table6<- xtabs(~fdi+ exchange.rate , data= ob2)
table6
## exchange.rate
## fdi 97.68 99.17 101.78 101.97 102.32 102.71 102.82 103.46 104.3
## 2187.85 0 1 0 0 0 0 0 0 0
## 2378.71 0 0 0 0 0 0 1 0 0
## 2704.32 1 0 0 0 0 0 0 0 0
## 3218.69 0 0 1 0 0 0 0 0 0
## 4027.69 0 0 0 0 0 1 0 0 0
## 5539.75 0 0 0 0 0 0 0 0 0
## 12491.76 0 0 0 0 0 0 0 0 1
## 21383.07 0 0 0 0 0 0 0 0 0
## 22423.59 0 0 0 0 0 0 0 0 0
## 24299.32 0 0 0 0 0 0 0 1 0
## 24575.4 0 0 0 0 0 0 0 0 0
## 25834.38 0 0 0 1 0 0 0 0 0
## 30930.47 0 0 0 0 0 0 0 0 0
## 31395.96 0 0 0 0 1 0 0 0 0
## 35120.78 0 0 0 0 0 0 0 0 0
## 40000.99 0 0 0 0 0 0 0 0 0
## exchange.rate
## fdi 105.13 105.17 106.1 106.3 111.86 112.76 114.91
## 2187.85 0 0 0 0 0 0 0
## 2378.71 0 0 0 0 0 0 0
## 2704.32 0 0 0 0 0 0 0
## 3218.69 0 0 0 0 0 0 0
## 4027.69 0 0 0 0 0 0 0
## 5539.75 0 1 0 0 0 0 0
## 12491.76 0 0 0 0 0 0 0
## 21383.07 0 0 0 0 0 0 1
## 22423.59 1 0 0 0 0 0 0
## 24299.32 0 0 0 0 0 0 0
## 24575.4 0 0 0 0 0 1 0
## 25834.38 0 0 0 0 0 0 0
## 30930.47 0 0 0 1 0 0 0
## 31395.96 0 0 0 0 0 0 0
## 35120.78 0 0 0 0 1 0 0
## 40000.99 0 0 1 0 0 0 0
table7<- xtabs(~inflation+ exchange.rate , data= ob2)
table7
## exchange.rate
## inflation 97.68 99.17 101.78 101.97 102.32 102.71 102.82 103.46 104.3
## 2.23 0 0 0 0 0 0 0 0 0
## 3.2 0 0 0 0 0 1 0 0 0
## 3.72 1 0 0 0 0 0 0 0 0
## 3.78 0 1 0 0 0 0 0 0 0
## 5.16 0 0 0 0 0 0 1 0 0
## 5.51 0 0 0 0 0 0 0 0 1
## 5.57 0 0 1 0 0 0 0 0 0
## 5.86 0 0 0 0 0 0 0 1 0
## 6.32 0 0 0 0 0 0 0 0 0
## 6.49 0 0 0 0 0 0 0 0 0
## 6.53 0 0 0 0 0 0 0 0 0
## 9.13 0 0 0 0 0 0 0 0 0
## 9.47 0 0 0 1 0 0 0 0 0
## 9.7 0 0 0 0 0 0 0 0 0
## 11.17 0 0 0 0 0 0 0 0 0
## 14.97 0 0 0 0 1 0 0 0 0
## exchange.rate
## inflation 105.13 105.17 106.1 106.3 111.86 112.76 114.91
## 2.23 0 0 1 0 0 0 0
## 3.2 0 0 0 0 0 0 0
## 3.72 0 0 0 0 0 0 0
## 3.78 0 0 0 0 0 0 0
## 5.16 0 0 0 0 0 0 0
## 5.51 0 0 0 0 0 0 0
## 5.57 0 0 0 0 0 0 0
## 5.86 0 0 0 0 0 0 0
## 6.32 0 0 0 1 0 0 0
## 6.49 0 0 0 0 0 0 1
## 6.53 0 1 0 0 0 0 0
## 9.13 1 0 0 0 0 0 0
## 9.47 0 0 0 0 0 0 0
## 9.7 0 0 0 0 0 1 0
## 11.17 0 0 0 0 1 0 0
## 14.97 0 0 0 0 0 0 0
Boxplots of the variables
boxplot(ob1$sector.total, xlab="Sector Total", main="Boxplot of Sector total of FDI for 16 years", horizontal = TRUE)
boxplot(ob2$fdi, xlab="FDI", main="Boxplot of FDI ", horizontal = TRUE, col = "blue")
boxplot(ob2$exchange.rate, xlab="Exchange Rate", main="Boxplot of Exchange Rate ", horizontal = TRUE, col = "red")
boxplot(ob2$inflation, xlab="Inflation Rate", ylab="Percentage", main="Boxplot Inflation Rate ", horizontal = TRUE, col = "yellow")
Histograms
hist(ob1$sector.total, col="purple", xlab="Sector Total",main="Boxplot of Sector total of FDI for 16 years")
hist(ob2$fdi , col="blue", xlab="FDI",main="Boxplot of FDI")
hist(ob2$exchange.rate , col="red", xlab="Exchange Rate",main="Boxplot of Exchange Rate")
hist(ob2$inflation , col="yellow", xlab="Inflation Rate",main="Boxplot of Inflation Rate")
a correlation matrix
options(digits = 2)
cor(ob2)
## years fdi inflation exchange.rate
## years 1.00 0.89 0.26 0.47
## fdi 0.89 1.00 0.48 0.53
## inflation 0.26 0.48 1.00 0.31
## exchange.rate 0.47 0.53 0.31 1.00
correlation matrix using corrgram.
library(corrgram)
corrgram(ob2, lower.panel = panel.shade, upper.panel = panel.pie ,text.panel = panel.txt, main="Corrgram of FDI, Inflation and Exchange rate")
A scatter plot matrix
library(car)
##
## Attaching package: 'car'
## The following object is masked from 'package:psych':
##
## logit
scatterplotMatrix(~ fdi+exchange.rate+ inflation, data= ob2,
main="FDI vs Inflation Vs Exchange Rtae")
A suitable test to check your hypothesis for your suitable assumptions.
1]FDI and inflation
chisq.test(table5)
## Warning in chisq.test(table5): Chi-squared approximation may be incorrect
##
## Pearson's Chi-squared test
##
## data: table5
## X-squared = 200, df = 200, p-value = 0.2
2]FDI and Exchange rate
chisq.test(table6)
## Warning in chisq.test(table6): Chi-squared approximation may be incorrect
##
## Pearson's Chi-squared test
##
## data: table6
## X-squared = 200, df = 200, p-value = 0.2
t-test
1]FDI and inflation
t.test(ob2$fdi, ob2$inflation, paired=TRUE)
##
## Paired t-test
##
## data: ob2$fdi and ob2$inflation
## t = 5, df = 20, p-value = 7e-05
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## 10975 25075
## sample estimates:
## mean of the differences
## 18025
2]FDI and Exchange rate
t.test(ob2$fdi, ob2$exchange.rate , paired=TRUE)
##
## Paired t-test
##
## data: ob2$fdi and ob2$exchange.rate
## t = 5, df = 20, p-value = 7e-05
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## 10877 24977
## sample estimates:
## mean of the differences
## 17927