Data Analysis for 203 Project
Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit
Data Analysis for 203 Project
Example of Analysis(Fertilizer)
With steps clearly illustrated in the guiding document, we are able to generate the following graphs that ought to be useful.
fert: Main DataSet of fertilizer consumption in KG per hectare of arable land.
g20Fert: DataSet for countries.
“T”: Transposed DataSet
“Pure”: Take out the Characters in the main dataframe.
A little function that eliminates the x before number-name columns
destroyX = function(es) {
f = es
for (col in c ( 1:ncol(f))){
if (startsWith (colnames(f)[col], "X") == TRUE){
colnames(f)[col] <- substr(colnames(f)[col], 2 , 100)
}
}
assign(deparse(substitute(es)), f, inherits = TRUE)
}
G20 Countries Country Code
g20State <- c ( "CAN" , "USA" , "AUS" , "GBR" , "FRA" , "DEU" , "ITA" , "JPN" , "BRA" , "RUS"
, "IND" , "CHN" , "ZAF" , "MEX" , "ARG" , "TUR" , "SAU" , "KOR" , "IDN" , "EUU")
The G20 consists of the G7, BRICS, and 7 other important economic entities, such as Australia, Saudi Arabia, and Rep.Korea.
Import Fertilizer Data
fert <- read .csv ("D://URochester/Course MATH 203 Intro to Math Stat/ProjectDataFile/FertilizerFile .csv") attach(fert)
g20Fert <- subset(fert, Country .Code %in% g20State, select = c (Country .Name:X2020)) detach(fert)
g20PureFert <- subset(g20Fert, select=c (X2000 :X2020))
g20Fert <- destroyX(g20Fert)
g20PureFert <- destroyX(g20PureFert)
Summary of Fertilizer Data for each year
library(stargazer)
##
## Please cite as:
## Hlavac, Marek (2022) . stargazer: Well-Formatted Regression and Summary Statistics Tables .
## R package version 5 .2 .3 . https://CRAN .R-project .org/package=stargazer
stargazer(g20Fert,type="text")
##
## ============================================
## Statistic N Mean St . Dev . Min Max
## --------------------------------------------
## 2000 20 159 .697 114 .156 11 .417 455 .959
## 2001 20 157 .321 110 .493 12 .940 424 .276
## 2002 20 156 .848 111 .543 11 .493 417 .970
## 2003 20 161 .765 111 .603 11 .004 427 .047
## 2004 20 165 .592 115 .577 11 .420 453 .196
## 2005 20 162 .075 119 .577 11 .793 478 .152
## 2006 20 155 .191 99 .196 12 .481 376 .726
## 2007 20 170 .420 110 .468 14 .253 406 .250
## 2008 20 143 .957 95 .007 15 .883 374 .214
## 2009 20 138 .830 95 .601 15 .635 385 .425
## 2010 20 154 .014 102 .862 15 .725 424 .378
## 2011 20 159 .436 105 .657 16 .187 440 .830
## 2012 20 162 .866 108 .068 15 .434 450 .769
## 2013 20 164 .896 106 .919 15 .298 449 .037
## 2014 20 169 .151 112 .641 15 .901 464 .776
## 2015 20 165 .258 108 .949 16 .663 464 .558
## 2016 20 167 .495 106 .353 18 .687 459 .090
## 2017 20 171 .167 105 .848 20 .328 445 .248
## 2018 20 169 .990 105 .230 20 .814 420 .359
## 2019 20 167 .722 100 .657 22 .591 398 .023
##
Boxplot for each Country in 2 decades
i <- 1
Tg20PureFert <- as .data .frame(t(g20PureFert))
colnames(Tg20PureFert) <- g20Fert[,1]
boxplot(Tg20PureFert$China, Tg20PureFert$`United States ` , Tg20PureFert$France,
horizontal = TRUE , xlab = "Fertilizer Usage(kg/ha)" ,
names = c ( "China" , "US" , "France"), main="Distribution of Fertilizer Usage(kg/ha) over 20 decades
Distribution of Fertilizer Usage(kg/ha) over 20 decades
|
400
Fertilizer Usage(kg/ha)
Time Series Plots
par (mfrow=c (2 ,2))
a <- c (2000:2020)
i <- 1
while(i < 21){
plot(a,g20PureFert[i,],type= 'l ' ,
main=g20Fert[i,1],xlab="Year" ,ylab="Fertilizer Usage(kg/ha)") i=i+1
}
2023-03-29