Population of Europe by Country: Difference between revisions

From Opasnet
Jump to navigation Jump to search
(An alternative data representation produced)
Line 3: Line 3:
== Scope ==
== Scope ==


===Indices===
=== Dimensions ===


*Country
*Country
Line 16: Line 16:


=== Data ===
=== Data ===
=== Unit ===
<nowiki>#</nowiki>
=== Formula ===
==== Reducing EMEP 50 grid -indexed data to country indexed ====


Constructed from data in [[Population of Europe]], by summing results for each country using the [[R]] code below. The code requires database functions described [[Opasnet Base Connection for R|here]].
Constructed from data in [[Population of Europe]], by summing results for each country using the [[R]] code below. The code requires database functions described [[Opasnet Base Connection for R|here]].


  locs <- op_baseGetLocs("opasnet_base", "Op_en3017")
  <nowiki>
countries <- locs[grep("CountryID", locs$ind),3]
locs <- op_baseGetLocs("opasnet_base", "Op_en3017")
i <- 1
countries <- locs[grep("CountryID", locs$ind),3]
data <- op_baseGetData("opasnet_base", "Op_en3017", include = countries[i])
i <- 1
data <- data[order(data[,3], data[,4], data[,7], data[,8], data[,9]),]
data <- op_baseGetData("opasnet_base", "Op_en3017", include = countries[i])
n <- data[gsub(" ", "", data[,"Age"])=="0-4",]
data <- data[order(data[,3], data[,4], data[,7], data[,8], data[,9]),]
n <- n[gsub(" ", "", n[,"Rate"])=="h",]
n <- data[gsub(" ", "", data[,"Age"])=="0-4",]
n <- n[gsub(" ", "", n[,"Sex"])=="Female",]
n <- n[gsub(" ", "", n[,"Rate"])=="h",]
n <- n[gsub(" ", "", n[,"Year"])=="2010",]
n <- n[gsub(" ", "", n[,"Sex"])=="Female",]
n <- nrow(n)
n <- n[gsub(" ", "", n[,"Year"])=="2010",]
data2 <- data[1:(nrow(data)/n),c("Age","CountryID","Rate","Sex","Year","Result")]
n <- nrow(n)
for (j in 1:(nrow(data)/n)) {
data2 <- data[1:(nrow(data)/n),c("Age","CountryID","Rate","Sex","Year","Result")]
data2[j,] <- data.frame(data[j*n-n+1,c("Age","CountryID","Rate","Sex","Year")], sum(data[(j*n-n+1):(j*n),"Result"]))
for (j in 1:(nrow(data)/n)) {
}
data2[j,] <- data.frame(data[j*n-n+1,c("Age","CountryID","Rate","Sex","Year")], sum(data[(j*n-n+1):(j*n),"Result"]))
op_baseWrite("opasnet_base", data2, ident = "Op_en4691", name = "Population of Europe by country", unit = "#", objtype_id = 1,  
}
who = "Teemu R", acttype = 4)
op_baseWrite("opasnet_base", data2, ident = "Op_en4691", name = "Population of Europe by country", unit = "#", objtype_id = 1,  
for (i in 2:length(countries)) {
who = "Teemu R", acttype = 4)
data <- op_baseGetData("opasnet_base", "Op_en3017", include = countries[i])
for (i in 2:length(countries)) {
data <- data[order(data[,3], data[,4], data[,7], data[,8], data[,9]),]
data <- op_baseGetData("opasnet_base", "Op_en3017", include = countries[i])
n <- data[gsub(" ", "", data[,"Age"])=="0-4",]
data <- data[order(data[,3], data[,4], data[,7], data[,8], data[,9]),]
n <- n[gsub(" ", "", n[,"Rate"])=="h",]
n <- data[gsub(" ", "", data[,"Age"])=="0-4",]
n <- n[gsub(" ", "", n[,"Sex"])=="Female",]
n <- n[gsub(" ", "", n[,"Rate"])=="h",]
n <- n[gsub(" ", "", n[,"Year"])=="2010",]
n <- n[gsub(" ", "", n[,"Sex"])=="Female",]
n <- nrow(n)
n <- n[gsub(" ", "", n[,"Year"])=="2010",]
data2 <- data[1:(nrow(data)/n),c("Age","CountryID","Rate","Sex","Year","Result")]
n <- nrow(n)
for (j in 1:(nrow(data)/n)) {
data2 <- data[1:(nrow(data)/n),c("Age","CountryID","Rate","Sex","Year","Result")]
data2[j,] <- data.frame(data[j*n-n+1,c("Age","CountryID","Rate","Sex","Year")], sum(data[(j*n-n+1):(j*n),"Result"]))
for (j in 1:(nrow(data)/n)) {
}
data2[j,] <- data.frame(data[j*n-n+1,c("Age","CountryID","Rate","Sex","Year")], sum(data[(j*n-n+1):(j*n),"Result"]))
op_baseWrite("opasnet_base", data2, ident = "Op_en4691", who = "Teemu R", acttype = 5)
}
}
op_baseWrite("opasnet_base", data2, ident = "Op_en4691", who = "Teemu R", acttype = 5)
}</nowiki>
 
==== Reducing population scenarios to probabilistic interpretation of reality ====


=== Unit ===
*Data generated by above code used for simplicity.
*Samples randomly picked from low, medium and high population growth scenarios with equal probabilities.


<nowiki>#</nowiki>
<nowiki>
pop <- op_baseGetData("opasnet_base", "Op_en4691", series_id = 596, include = 1367) #Only data for all ages downloaded to conserve memory
poparray <- DataframeToArray(pop[,c("obs","Age","CountryID","Sex","Year","Rate","Result")])
poparray[,"EE","Male","2050","m"] <- poparray[,"EE","All","2050","m"] - poparray[,"EE","Female","2050","m"]
poparray[,"EE","All","2050","h"] <- poparray[,"EE","Male","2050","h"] + poparray[,"EE","Female","2050","h"]
#There are some flaws in the original data, these are patched up above
n <- 5000
finalarray <- array(poparray[,,,,sample(1:3, n, replace = TRUE)], dim = c(dim(poparray)[1:(length(dim(poparray))-1)], n))
dimnames(finalarray) <- c(dimnames(poparray)[1:4], list(obs = 1:n))
final <- as.data.frame(as.table(finalarray))
nrow(final[is.na(final[,"Freq"]),])</nowiki>


== Result ==
== Result ==

Revision as of 12:42, 26 January 2011


Scope

Dimensions

  • Country
  • Year
    • 2010, 2020, 2030, 2050
  • Sex
  • Age
  • Growth rate
    • high, medium, low

Definition

Data

Unit

#

Formula

Reducing EMEP 50 grid -indexed data to country indexed

Constructed from data in Population of Europe, by summing results for each country using the R code below. The code requires database functions described here.

locs <- op_baseGetLocs("opasnet_base", "Op_en3017")
countries <- locs[grep("CountryID", locs$ind),3]
i <- 1
data <- op_baseGetData("opasnet_base", "Op_en3017", include = countries[i])
data <- data[order(data[,3], data[,4], data[,7], data[,8], data[,9]),]
n <- data[gsub(" ", "", data[,"Age"])=="0-4",]
n <- n[gsub(" ", "", n[,"Rate"])=="h",]
n <- n[gsub(" ", "", n[,"Sex"])=="Female",]
n <- n[gsub(" ", "", n[,"Year"])=="2010",]
n <- nrow(n)
data2 <- data[1:(nrow(data)/n),c("Age","CountryID","Rate","Sex","Year","Result")]
for (j in 1:(nrow(data)/n)) {
	data2[j,] <- data.frame(data[j*n-n+1,c("Age","CountryID","Rate","Sex","Year")], sum(data[(j*n-n+1):(j*n),"Result"]))
}
op_baseWrite("opasnet_base", data2, ident = "Op_en4691", name = "Population of Europe by country", unit = "#", objtype_id = 1, 
who = "Teemu R", acttype = 4)
for (i in 2:length(countries)) {
	data <- op_baseGetData("opasnet_base", "Op_en3017", include = countries[i])
	data <- data[order(data[,3], data[,4], data[,7], data[,8], data[,9]),]
	n <- data[gsub(" ", "", data[,"Age"])=="0-4",]
	n <- n[gsub(" ", "", n[,"Rate"])=="h",]
	n <- n[gsub(" ", "", n[,"Sex"])=="Female",]
	n <- n[gsub(" ", "", n[,"Year"])=="2010",]
	n <- nrow(n)
	data2 <- data[1:(nrow(data)/n),c("Age","CountryID","Rate","Sex","Year","Result")]
	for (j in 1:(nrow(data)/n)) {
		data2[j,] <- data.frame(data[j*n-n+1,c("Age","CountryID","Rate","Sex","Year")], sum(data[(j*n-n+1):(j*n),"Result"]))
	}
	op_baseWrite("opasnet_base", data2, ident = "Op_en4691", who = "Teemu R", acttype = 5)
}

Reducing population scenarios to probabilistic interpretation of reality

  • Data generated by above code used for simplicity.
  • Samples randomly picked from low, medium and high population growth scenarios with equal probabilities.
pop <- op_baseGetData("opasnet_base", "Op_en4691", series_id = 596, include = 1367) #Only data for all ages downloaded to conserve memory
poparray <- DataframeToArray(pop[,c("obs","Age","CountryID","Sex","Year","Rate","Result")])
poparray[,"EE","Male","2050","m"] <- poparray[,"EE","All","2050","m"] - poparray[,"EE","Female","2050","m"]
poparray[,"EE","All","2050","h"] <- poparray[,"EE","Male","2050","h"] + poparray[,"EE","Female","2050","h"]
#There are some flaws in the original data, these are patched up above
n <- 5000
finalarray <- array(poparray[,,,,sample(1:3, n, replace = TRUE)], dim = c(dim(poparray)[1:(length(dim(poparray))-1)], n))
dimnames(finalarray) <- c(dimnames(poparray)[1:4], list(obs = 1:n))
final <- as.data.frame(as.table(finalarray))
nrow(final[is.na(final[,"Freq"]),])

Result

{{#opasnet_base_link:Op_en4691}}


See also

References