Question
How Baltic herring and salmon are used as human food in Baltic sea countries? Which determinants affect on people’s eating habits of these fish species?
Answer
Survey data will be analysed during winter 2016-2017 and results will be updated here.
Rationale
Survey of eating habits of Baltic herring and salmon in Denmark, Estonia, Finland and Sweden has been done in September 2016 by Taloustutkimus oy. Content of the questionnaire can be accessed in Google drive. The actual data will be uploaded to Opasnet base on Octobere 2016.
The R-code to analyse the survey data will be provided in this page later on.
Data
Original datafile File:Goherr fish consumption.csv
Preprocessing
+ Show code- Hide code
library(OpasnetUtils)
library(reshape2)
library(ggplot2)
############## Generic functions and objects are defined first.
### webropol.convert converts a csv file from Webropol into a useful data.frame.
webropol.convert <- function(
data, # Data.frame created from a Webropol csv file. The first row should contain headings.
rowfact, # Row number where the factor levels start (in practice, last row + 3)
textmark = "Other open" # The text that is shown in the heading if there is an open sub-question.
) {
out <- dropall(data[2:(rowfact - 3) , ])
subquestion <- t(data[1 , ])
subquestion <- gsub("\xa0", " ", subquestion)
subquestion <- gsub("\xb4", " ", subquestion)
subquestion <- gsub("\n", " ", subquestion)
# subquestion <- gsub("\\(", " ", subquestion)
# subquestion <- gsub("\\)", " ", subquestion)
textfield <- regexpr(textmark, subquestion) != -1
subquestion <- strsplit(subquestion, ":") # Divide the heading into a main question and a subquestion.
subqtest <- 0 # The previous question name.
for(i in 1:ncol(out)) {
print(i)
if(subquestion[[i]][1] != subqtest) { # If part of previous question, use previous fact.
fact <- as.character(data[rowfact:nrow(data) , i]) # Create factor levels from the end of Webropol file.
fact <- fact[fact != ""] # Remove empty rows
fact <- gsub("\xa0", " ", fact)
fact <- gsub("\xb4", " ", fact)
fact <- gsub("\n", " ", fact)
fact <- strsplit(fact, " = ") # Separate value (level) and interpretation (label)
}
if(length(fact) != 0 & !textfield[i]) { # Do this only if the column is not a text type column.
out[[i]] <- factor(
out[[i]],
levels = unlist(lapply(fact, function(x) x[1])),
labels = unlist(lapply(fact, function(x) x[2])),
ordered = TRUE
)
}
subqtest <- subquestion[[i]][1]
}
return(out)
}
# merge.questions takes a multiple checkbox question and merges that into a single factor.
# First levels in levs have priority over others, if several levels apply to a row.
merge.questions <- function(
dat, # data.frame with questionnaire data
cols, # list of vectors of column names or numbers to be merged into one level in the factor
levs, # vector (with the same length as cols) of levels of factors into which questions are merged.
name # text string for the name of the new factor column in the data.
) {
for(i in length(cols):1) {
temp <- FALSE
for(j in rev(cols[[i]])) {
temp <- temp | !is.na(dat[[j]])
}
dat[[name]][temp] <- levs[i]
}
dat[[name]] <- factor(dat[[name]], levels = levs, ordered = TRUE)
return(dat)
}
############# Data preprocessing
# Get the data either from Opasnet or your own hard drive.
#Survey original file: N:/Ymal/Projects/Goherr/WP5/Goherr_fish_consumption.csv
survey <- opasnet.csv("5/57/Goherr_fish_consumption.csv", sep = ";", fill = TRUE, quote = "\"")
surcol <- t(survey[1,])
survey <- webropol.convert(survey, 2121, textmark = ":Other open") # Data file is converted to data.frame using levels at row 1269.
# Take the relevant columnames from the table on the page.
#colnames(survey1) <- opbase.data("Heande3951",subset="Survey 1 questions")[1:ncol(survey1), "Name"]
ggplot(survey, aes(x = as.numeric(V4), fill = V3)) + geom_histogram(position = "dodge") +
theme_gray(base_size = 18) + theme(axis.text.x=element_text(angle=90,hjust=1,vjust=0.4)) + facet_wrap(~ V1)
| |
Dependencies
The survey data will be used as input in the benefit-risk assessment of Baltic herring and salmon intake, which is part of the WP5 work in Goherr-project.
Formula
See also
Keywords
References
Related files
<mfanonymousfilelist></mfanonymousfilelist>
- Goherr: Fish consumption study. Opasnet . [1]. Accessed 20 May 2024.