Difference between revisions of "Goherr: Fish consumption study"

From Testiwiki
Jump to: navigation, search
m (Calculations)
(Bayes: bayes model split and moved from Benefit-risk assessment of Baltic herring and salmon intake and updated to include non-fish consumers)
Line 215: Line 215:
 
cat("objects survey, surcol were stored.\n")
 
cat("objects survey, surcol were stored.\n")
  
 +
</rcode>
 +
 +
==== Bayes model ====
 +
 +
* Model run 3.3.2017. All variables assumed independent. [http://en.opasnet.org/en-opwiki/index.php?title=Special:RTools&id=lwlSwXazIDHDyJJg]
 +
 +
<rcode name="bayes" label="Initiate Bayes model (for developers only)" graphics=1>
 +
# This is code Op_en7749/bayes on page [[Goherr: Fish consumption study]]
 +
 +
library(OpasnetUtils)
 +
library(reshape2)
 +
library(rjags)
 +
library(car)
 +
 +
# Fish intake in humans
 +
# Data from data.frame survey from page [[Goherr: Fish consumption study]]
 +
# Start with salmon questions 46:49 (amounts eaten)
 +
# Some preprocessing should be moved away from this code.
 +
# Model assumes that questionnaire data follows binomial distribution with parameter p and max value 9.
 +
# 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.
 +
# Predicted p for each question, determined by the group, are produced from the bayes model.
 +
# p is used to sample answers, which are then combined with estimates of amounts related to each answer.
 +
# Total amount eaten of each fish per modelled individual is finally calculated.
 +
 +
objects.latest("Op_en7749", "preprocess") # [[Goherr: Fish consumption study]]: survey, surcol
 +
 +
# Interesting fish eating questions
 +
surv <- survey[c(1,3,4,16,29,30,31,46:49,86,95:98,158)]
 +
colnames(surv)
 +
 +
consume <- data.matrix(survey[c(
 +
  "Baltic salmon",
 +
  "Eat Baltic herring"
 +
)])
 +
consume <- 1 - (consume!=2 | is.na(consume)) # Yes=1, other=0
 +
 +
agel <- as.character(unique(survey$Ages))
 +
countryl <- sort(as.character(unique(survey$Country)))
 +
genderl <- sort(as.character(unique(survey$Gender)))
 +
fisl <- c("Salmon", "Herring")
 +
 +
ans.sal <- survey[
 +
    grep("Yes", survey[["Baltic salmon"]]) ,
 +
    c(
 +
      "How often Baltic salmon",
 +
      "How much Baltic salmon",
 +
      "How often side Baltic salmon",
 +
      "How much side Baltic salmon",
 +
      "Ages",
 +
      "Country",
 +
      "Gender"
 +
    )]
 +
 +
ans.her <- survey[
 +
    grep("Yes", survey[["Eat Baltic herring"]]) ,
 +
    c(
 +
      "How often Baltic herring",
 +
      "How much Baltic herring",
 +
      "How often side Baltic herring",
 +
      "How much side Baltic herring",
 +
      "Ages",
 +
      "Country",
 +
      "Gender"
 +
    )]
 +
coln <-    c(
 +
  "How often",
 +
  "How much",
 +
  "How often side",
 +
  "How much side",
 +
  "Ages",
 +
  "Country",
 +
  "Gender"
 +
)
 +
colnames(ans.sal) <- coln
 +
colnames(ans.her) <- coln
 +
ans <- rbind(ans.sal, ans.her)
 +
 +
head(ans)
 +
qlen <-  c(7,7,7,5) # Previously was calculated from data: unlist(lapply(
 +
#  surv,
 +
#  FUN = function(x) {length(levels(x))}))[-c(1:3, ncol(surv))]
 +
#questionl <- colnames(surv)
 +
questionl <- colnames(ans.sal)
 +
questionl.her <- colnames(ans.her)
 +
 +
agel
 +
countryl
 +
genderl
 +
fisl
 +
 +
mod <- textConnection("
 +
  model{
 +
    for(f in 1:2) { # Salmon or herring
 +
      for(i in 1:U) { # Full questionnaire
 +
        consume[i,f] ~ dbern(p[f])
 +
      }
 +
      p[f] ~ dbeta(1,1)
 +
    }
 +
    for(q in 1:Q) { # Q = # of fish-specific questions
 +
      for(i in 1:S) { # S = # respondents who eat Baltic salmon or herring
 +
        ans[i,q] ~ dbin(p2[fis[i],age[i],country[i],gender[i],q], qlen[q])
 +
      }
 +
      for(i in 1:A) { # Age groups
 +
        for(j in 1:C) { # Countries
 +
          for(k in 1:G) { #Genders
 +
            for(f in 1:2) { # Fish species
 +
              p2[f,i,j,k,q] ~ dunif(0,1)
 +
              ans.pred[f,i,j,k,q] ~ dbin(p2[f,i,j,k,q], qlen[q])
 +
            }
 +
          }
 +
        }
 +
      }
 +
    }
 +
  }
 +
")
 +
 +
jags <- jags.model(
 +
  mod,
 +
  data = list(
 +
    U = nrow(surv),
 +
    Q = 4,
 +
    S = nrow(ans),
 +
    consume = consume,
 +
    ans = data.matrix(ans[1:4]) - 1, # Zero is the first option
 +
    qlen = qlen-1, # Subtract 1 because starts from 0.
 +
    age = match(ans$Ages, agel),
 +
    country = match(ans$Country, countryl),
 +
    gender = match(ans$Gender, genderl),
 +
    fis = c(rep(1, nrow(ans.sal)), rep(2, nrow(ans.her))),
 +
#    Ys = grep("Yes", survey[["Baltic salmon"]]),
 +
#    Yh = grep("Yes", survey[["Eat Baltic herring"]]),
 +
    A = length(agel),
 +
    C = length(countryl),
 +
    G = length(genderl)
 +
  ),
 +
  n.chains = 4,
 +
  n.adapt = 100
 +
)
 +
 +
update(jags, 100)
 +
samps <- jags.samples(jags, c('ans.pred','p','p2'), 1000)
 +
#samps.coda <- coda.samples(jags, c('mu', 'pcd.pred', 'ans.pred'), 1000)
 +
 +
ans.pred <- array(
 +
  samps$ans.pred,
 +
  dim = c(length(fisl), length(agel), length(countryl), length(genderl), length(coln), 1000, 4),
 +
  dimnames = list(
 +
    Fish = fisl,
 +
    Age = agel,
 +
    Country = countryl,
 +
    Gender = genderl,
 +
    Question = coln,
 +
    Iter = 1:1000,
 +
    Seed = c("S1","S2","S3","S4")
 +
  )
 +
)
 +
 +
p.pred <- array(
 +
  samps$p,
 +
  dim = c(length(fisl), 1000, 4),
 +
  dimnames = list(
 +
    Fish = fisl,
 +
    Iter = 1:1000,
 +
    Seed = c("S1","S2","S3","S4")
 +
  )
 +
)
 +
 +
p2.pred <- array(
 +
  samps$p2,
 +
  dim = c(length(fisl), length(agel), length(countryl), length(genderl), length(coln), 1000, 4),
 +
  dimnames = list(
 +
    Fish = fisl,
 +
    Age = agel,
 +
    Country = countryl,
 +
    Gender = genderl,
 +
    Question = coln,
 +
    Iter = 1:1000,
 +
    Seed = c("S1","S2","S3","S4")
 +
  )
 +
)
 +
 +
ansm <- melt(ans.pred)
 +
pm <- melt(p.pred)
 +
p2m <- melt(p2.pred)
 +
 +
scatterplotMatrix(t(ans.pred[1,1,,1,1,,1]))
 +
 +
scatterplotMatrix(t(p2.pred[1,1,,1,1,,1]))
 +
scatterplotMatrix(t(p2.pred[,1,3,1,1,,1]))
 +
scatterplotMatrix(t(p2.pred[1,,3,1,1,,1]))
 +
scatterplotMatrix(t(p2.pred[1,1,3,,1,,1]))
 +
scatterplotMatrix(t(p2.pred[1,1,3,1,,,1]))
 +
 +
scatterplotMatrix(t(p.pred[,,1]))
 +
 +
objects.store(ans.pred, p.pred, p2.pred)
 +
cat("Arrays ans.pred (answer), p.pred (probability to eat), p2.pred (p of answer) stored.\n")
 
</rcode>
 
</rcode>
  

Revision as of 13:07, 3 March 2017


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.

+ Show code

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.

+ Show code

Bayes model

  • Model run 3.3.2017. All variables assumed independent. [1]

+ Show code

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.

+ Show code

Assumptions

The following assumptions are used:

Assumptions for calculations(-)
ObsVariablevalueExplanationResult
1freq6times per year260 - 364
2freq5times per year104 - 208
3freq4times per year52
4freq3times per year12 - 36
5freq2times per year2 - 5
6freq1times per year0.5 - 0.9
7freq0times per year0
8amdish0grams / serving20 - 50
9amdish1grams / serving70 - 100
10amdish2grams / serving120 - 150
11amdish3grams / serving170 - 200
12amdish4grams / serving220 - 250
13amdish5grams / serving270 - 300
14amdish6grams / serving450 - 500
15ingridientfraction0.1 - 0.3
16amside0grams / serving20 - 50
17amside1grams / serving70 - 100
18amside2grams / serving120 - 150
19amside3grams / serving170 - 200
20amside4grams / serving220 - 250

Questionnaire


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 . [2]. Accessed 17 May 2024.