NOTE THAT ((This should be done by R studio !)) Please a. Read the data file the
ID: 3219062 • Letter: N
Question
NOTE THAT
((This should be done by R studio !))
Please
a. Read the data file then do any cleaning and validation.
b. Apply two OLS regression by R studio :
The first model:
(Food exports (% of merchandise exports)) is the dependent variable, The independent variables are OilP and REX.
The second model:
"Ores and metals exports (% of merchandise exports)" is the dependent variable, The independent variables are OilP and REX.
Year
REX
OilP
Food exports (% of merchandise exports)
Ores and metals exports (% of merchandise exports)
1980
239.5433424
35.52
0.09638294
0.060083757
1981
240.3102173
34
0.094079554
0.024360528
1982
245.3895131
32.38
0.128489839
0.025668368
1983
242.8677506
29.04
..
..
1984
238.0284197
28.2
..
..
1985
221.878717
27.01
0.259787311
0.116943755
1986
169.6457184
13.53
..
..
1987
144.1934823
17.73
..
..
1988
134.5212315
14.24
1.371078529
0.732151804
1989
136.0536024
17.31
1.374888969
0.834330299
1990
125.5311345
22.26
0.713126234
0.491007478
1991
125.8812467
18.62
0.526384845
0.242750346
1992
118.7733668
18.44
1.074388363
0.548851562
1993
122.2521688
16.33
0.982275388
0.429968062
1994
117.8952881
15.53
0.673955645
0.346686956
1995
114.1213899
16.86
0.810242733
0.567217625
1996
116.3114665
20.29
0.632336949
0.304958406
1997
121.4661302
18.86
..
..
1998
127.1948915
12.28
1.114818605
0.507089276
1999
121.9490893
17.44
0.930990348
0.262574488
2000
123.200674
27.6
0.538501429
0.147164016
2001
125.2424379
23.12
0.558465111
0.201693533
2002
121.5455166
24.36
0.628539417
0.223275991
2003
111.1523893
28.1
0.835851768
0.182707717
2004
103.4682918
36.05
0.7405123
0.172800798
2005
100.5070052
50.59
0.620831971
0.137293785
2006
98.93290899
61
0.64203501
0.219532433
2007
95.96813741
69.04
0.838923226
0.283587719
2008
93.62494305
94.1
0.744029125
0.221986187
2009
100.1652448
60.86
1.407633083
0.232499732
2010
100
77.38
1.155876888
0.154654215
2011
96.57013945
107.46
0.898301922
0.122271232
2012
99.61967144
109.45
0.860627792
0.138455596
2013
102.3680362
105.87
0.878931429
0.403127249
2014
105.3894897
96.29
1.006265279
0.769034983
2015
118.5851177
49.49
1.798068624
1.307540253
R ONLY !!
Year
REX
OilP
Food exports (% of merchandise exports)
Ores and metals exports (% of merchandise exports)
1980
239.5433424
35.52
0.09638294
0.060083757
1981
240.3102173
34
0.094079554
0.024360528
1982
245.3895131
32.38
0.128489839
0.025668368
1983
242.8677506
29.04
..
..
1984
238.0284197
28.2
..
..
1985
221.878717
27.01
0.259787311
0.116943755
1986
169.6457184
13.53
..
..
1987
144.1934823
17.73
..
..
1988
134.5212315
14.24
1.371078529
0.732151804
1989
136.0536024
17.31
1.374888969
0.834330299
1990
125.5311345
22.26
0.713126234
0.491007478
1991
125.8812467
18.62
0.526384845
0.242750346
1992
118.7733668
18.44
1.074388363
0.548851562
1993
122.2521688
16.33
0.982275388
0.429968062
1994
117.8952881
15.53
0.673955645
0.346686956
1995
114.1213899
16.86
0.810242733
0.567217625
1996
116.3114665
20.29
0.632336949
0.304958406
1997
121.4661302
18.86
..
..
1998
127.1948915
12.28
1.114818605
0.507089276
1999
121.9490893
17.44
0.930990348
0.262574488
2000
123.200674
27.6
0.538501429
0.147164016
2001
125.2424379
23.12
0.558465111
0.201693533
2002
121.5455166
24.36
0.628539417
0.223275991
2003
111.1523893
28.1
0.835851768
0.182707717
2004
103.4682918
36.05
0.7405123
0.172800798
2005
100.5070052
50.59
0.620831971
0.137293785
2006
98.93290899
61
0.64203501
0.219532433
2007
95.96813741
69.04
0.838923226
0.283587719
2008
93.62494305
94.1
0.744029125
0.221986187
2009
100.1652448
60.86
1.407633083
0.232499732
2010
100
77.38
1.155876888
0.154654215
2011
96.57013945
107.46
0.898301922
0.122271232
2012
99.61967144
109.45
0.860627792
0.138455596
2013
102.3680362
105.87
0.878931429
0.403127249
2014
105.3894897
96.29
1.006265279
0.769034983
2015
118.5851177
49.49
1.798068624
1.307540253
Explanation / Answer
The data was first saved as a .csv file and was then read into R. Since the data had 5 missing values, they were imputed using the corresponding column mean. Two linear regression models were then fit to the data.
The first model was fitted with Food.exports....of.merchandise.exports. as the dependent variable and OilP & REX as independent variable. It only had a R2 of 0.223 (which is pretty low) with only REX having significance i.e. REX is the only factor that have some effect on the dependent variable; OilP does not seem to have any significant effect to the dependent variable.
The second model was fitted with Ores.and.metals.exports....of.merchandise.exports. as the dependent variable and OilP & REX as independent variable. This also had a very low R2 of 0.0934 with no independent variables showing any significance. Thus, there are other factors that effect the dependent variable and these do independent variables do explain any variation of the dependent variable.
The R code for the same is attached below.
########## R CODE ############
# reading data
data1 = read.csv("C:\Users\Admin\Desktop\data1.csv")
summary(data1)
#no of missing values before imputation
apply(is.na(data1),2,sum)
#there are 5 missing observations. imputing missing value with mean
for(i in 1:ncol(data1)){
data1[is.na(data1[,i]), i] <- mean(data1[,i], na.rm = TRUE)
}
#no of missing values after imputation
apply(is.na(data1),2,sum)
#model 1
model1 = lm(Food.exports....of.merchandise.exports. ~ OilP + REX, data=data1)
summary(model1)
#model 2
model2 = lm(Ores.and.metals.exports....of.merchandise.exports. ~ OilP + REX, data=data1)
summary(model2)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.