Goherr: Fish consumption study: Difference between revisions
m (→Answer) |
(→Bayes model: tried to develop a fancier model but failed) |
||
Line 236: | Line 236: | ||
# Start with salmon questions 46:49 (amounts eaten) | # Start with salmon questions 46:49 (amounts eaten) | ||
# Some preprocessing should be moved away from this code. | # Some preprocessing should be moved away from this code. | ||
# Model assumes that questionnaire data follows binomial distribution with parameter p and max value | # Model assumes that questionnaire data follows binomial distribution with parameter p and max value levels. | ||
# p depends on country (4 groups), sex (2), age (2) that are known individually. | # p depends on country (4 groups), sex (2), age (2) that are known individually. | ||
# We should test whether sex makes a difference or whether it can be omitted. | # We should test whether sex makes a difference or whether it can be omitted. | ||
Line 244: | Line 244: | ||
objects.latest("Op_en7749", "preprocess") # [[Goherr: Fish consumption study]]: survey, surcol | objects.latest("Op_en7749", "preprocess") # [[Goherr: Fish consumption study]]: survey, surcol | ||
agel <- as.character(unique(survey$Ages)) | |||
countryl <- sort(as.character(unique(survey$Country))) | |||
genderl <- sort(as.character(unique(survey$Gender))) | |||
fisl <- c("Salmon", "Herring") | |||
# Interesting fish eating questions | |||
surv <- survey[c(1,3,158,16,29,30,31,46:49,86,95:98)] | |||
colnames(surv) | |||
#[1] "Country" "Gender" | |||
#[3] "Ages" "Fish eating" | |||
#[5] "How often eat fish" "Salmon eating" | |||
#[7] "Baltic salmon" "How often Baltic salmon" | |||
#[9] "How much Baltic salmon" "How often side Baltic salmon" | |||
#[11] "How much side Baltic salmon" "Eat Baltic herring" | |||
#[13] "How often Baltic herring" "How much Baltic herring" | |||
#[15] "How often side Baltic herring" "How much side Baltic herring" | |||
surv$Ages <- match(surv$Ages, agel) # Not a factor, coerce to integer | |||
surv <- as.data.frame(lapply(surv, FUN = function(x) as.integer(x))) # Coerce to integers | |||
surv[is.na(surv[[12]]) | surv[[12]] == 3 , 12] <- 1 # Eat Baltic herring: I don't know --> No | |||
surv[4:16] <- lapply(surv[4:16], FUN = function(x) x-1) # Scale to start from zero | |||
# Row numbers for respondents that have eaten fish, Baltic salmon, and Baltic herring | |||
eatfish <- (1:nrow(surv))[surv[[4]] %in% 1] | |||
eatsalm <- (1:nrow(surv))[!(surv[[7]] %in% 0 | is.na(surv[[7]]))] | |||
eatherr <- (1:nrow(surv))[surv[[12]] %in% 1 & !is.na(rowSums(surv[13:16]))] | |||
# Oletetaan, että covarianssimatriisi on vakio kaikille maille ja sukupuolille yms | |||
# mutta keskiarvo on spesifi näille ja kysymykselle. | |||
qlen <- c(4,2,2,2,6,2,2,7,7,7,5,2,7,7,7,5) # Number of options in each question | |||
agel | |||
countryl | |||
genderl | |||
fisl | |||
############ Version with both binomial and multivariate normal | |||
mod <- textConnection(" | |||
model{ | |||
for(i in 1:S) { | |||
for(j in 1:4) { | |||
surv[i,j] ~ dbin(phi(z[j]), qlen[j]) | |||
} | |||
} | |||
z[1:4] ~ dmnorm(mu[], Omega[,]) | |||
mu[1:4] ~ dmnorm(mu0[1:4], S2[1:4,1:4]) | |||
Omega[1:4,1:4] ~ dwish(S3[1:4,1:4],4) | |||
} | |||
") | |||
jags <- jags.model( | |||
mod, | |||
data = list( | |||
surv = surv[eatherr,13:16], | |||
qlen = qlen[13:16], | |||
S = length(eatherr), | |||
mu0 = rep(0.5,4), | |||
S2 = diag(4)/100000, | |||
S3 = diag(4)/10000 | |||
), | |||
n.chains = 4, | |||
n.adapt = 100 | |||
) | |||
update(jags, 100) | |||
samps.j <- jags.samples(jags, c('mu','Omega', 'z'), 1000) | |||
j <- array( | |||
samps.j$mu, | |||
dim = c(4,1000,4), | |||
dimnames = list(Question = 1:4, Iter = 1:1000, Seed = 1:4) | |||
) | |||
scatterplotMatrix(t(j[,,1])) | |||
samps.c <- coda.samples(jags, c('mu','Omega','z'), 1000) | |||
plot(samps.c) | |||
############################## | |||
############ Version with multivariate normal | |||
mod <- textConnection(" | |||
model{ | |||
for(i in 1:S) { | |||
surv[i,1:4] ~ dmnorm(mu[], Omega[,]) | |||
} | |||
mu[1:4] ~ dmnorm(mu0[1:4], S2[1:4,1:4]) | |||
Omega[1:4,1:4] ~ dwish(S3[1:4,1:4],4) | |||
} | |||
") | |||
jags <- jags.model( | |||
mod, | |||
data = list( | |||
surv = surv[eatherr,13:16], | |||
S = length(eatherr), | |||
mu0 = rep(0.5,4), | |||
S2 = diag(4)/100000, | |||
S3 = diag(4)/10000 | |||
), | |||
n.chains = 4, | |||
n.adapt = 100 | |||
) | |||
update(jags, 100) | |||
samps.j <- jags.samples(jags, c('mu','Omega', 'z'), 1000) | |||
j <- array( | |||
samps.j$mu, | |||
dim = c(4,1000,4), | |||
dimnames = list(Question = 1:4, Iter = 1:1000, Seed = 1:4) | |||
) | |||
scatterplotMatrix(t(j[,,1])) | |||
samps.c <- coda.samples(jags, c('mu','Omega','z'), 1000) | |||
plot(samps.c) | |||
############################## | |||
########### MODEL WITH BINOMIAL DISTRIBUTION ASSUMPTION | |||
# Interesting fish eating questions | # Interesting fish eating questions |
Revision as of 15:44, 23 March 2017
Moderator:Arja (see all) |
This page is a stub. You may improve it into a full page. |
Upload data
|
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 on this page later on.
Data
Original datafile File:Goherr fish consumption.csv
Preprocessing
This code is used to preprocess the original questionnaire data from the above .csv file and to store the data as a usable variable to Opasnet base.
Bayes model
- Model run 3.3.2017. All variables assumed independent. [1]
- Model run 3.3.2017. p has more dimensions. [2]
Calculations
This code calculates how much (g/day) Baltic herring and salmon are eaten based on an Bayesian model build up based on the questionnaire data.
Assumptions
The following assumptions are used:
Obs | Variable | value | Explanation | Result |
---|---|---|---|---|
1 | freq | 6 | times per year | 260 - 364 |
2 | freq | 5 | times per year | 104 - 208 |
3 | freq | 4 | times per year | 52 |
4 | freq | 3 | times per year | 12 - 36 |
5 | freq | 2 | times per year | 2 - 5 |
6 | freq | 1 | times per year | 0.5 - 0.9 |
7 | freq | 0 | times per year | 0 |
8 | amdish | 0 | grams / serving | 20 - 50 |
9 | amdish | 1 | grams / serving | 70 - 100 |
10 | amdish | 2 | grams / serving | 120 - 150 |
11 | amdish | 3 | grams / serving | 170 - 200 |
12 | amdish | 4 | grams / serving | 220 - 250 |
13 | amdish | 5 | grams / serving | 270 - 300 |
14 | amdish | 6 | grams / serving | 450 - 500 |
15 | ingridient | fraction | 0.1 - 0.3 | |
16 | amside | 0 | grams / serving | 20 - 50 |
17 | amside | 1 | grams / serving | 70 - 100 |
18 | amside | 2 | grams / serving | 120 - 150 |
19 | amside | 3 | grams / serving | 170 - 200 |
20 | amside | 4 | grams / serving | 220 - 250 |
Questionnaire
Show details | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
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>