Difference between revisions of "Goherr: Fish consumption study"

From Testiwiki
Jump to: navigation, search
(Bayes model)
(Bayes model: ovariables from bayes model stored)
Line 227: Line 227:
 
* Other models except multivariate normal were [http://en.opasnet.org/en-opwiki/index.php?title=Goherr:_Fish_consumption_study&oldid=40185 archived] and removed from active code 29.3.2017.
 
* Other models except multivariate normal were [http://en.opasnet.org/en-opwiki/index.php?title=Goherr:_Fish_consumption_study&oldid=40185 archived] and removed from active code 29.3.2017.
 
* Model run 29.3.2017 with raw data graphs [http://en.opasnet.org/en-opwiki/index.php?title=Special:RTools&id=BB8nePJb7hzSw6Ha]
 
* Model run 29.3.2017 with raw data graphs [http://en.opasnet.org/en-opwiki/index.php?title=Special:RTools&id=BB8nePJb7hzSw6Ha]
 +
* Model run 29.3.2017 with salmon and herring ovariables stored [http://en.opasnet.org/en-opwiki/index.php?title=Special:RTools&id=2Hz4tYjrQLnUfIXw]
  
 
<rcode name="bayes" label="Initiate Bayes model (for developers only)" graphics=1>
 
<rcode name="bayes" label="Initiate Bayes model (for developers only)" graphics=1>
Line 266: Line 267:
 
#[13] "How often Baltic herring"      "How much Baltic herring"       
 
#[13] "How often Baltic herring"      "How much Baltic herring"       
 
#[15] "How often side Baltic herring" "How much side Baltic herring"  
 
#[15] "How often side Baltic herring" "How much side Baltic herring"  
 +
test <- sapply(unique(surv[c(4,7,12)]), unique)#function(x) sum(is.na(x)))
 +
 +
oprint(table(surv[c(12,7,4)], useNA = "ifany"))
 +
oprint(table(surv[c(13,12)], useNA = "ifany"))
 +
# For estimating distributions, we should
 +
#1 remove people with Fish eating = No (142)
 +
#2 merge Eat Baltic herring = I don't know with No (How often BH = NA always)
 +
#3 merge Baltic salmon = NA with No (because they usually have answered BH questions)
 +
 +
oprint(table(is.na(rowSums(sapply(surv[4:16], as.numeric)))))
 +
# BUT: there are so many missing values, that we just model BH and BS separately now.
  
 
surv$Ages <- match(surv$Ages, agel) # Not a factor, coerce to integer
 
surv$Ages <- match(surv$Ages, agel) # Not a factor, coerce to integer
Line 274: Line 286:
 
# Row numbers for respondents that have eaten fish, Baltic salmon, and Baltic herring
 
# Row numbers for respondents that have eaten fish, Baltic salmon, and Baltic herring
 
eatfish <- surv[[4]] %in% 1
 
eatfish <- surv[[4]] %in% 1
eatsalm <- (1:nrow(surv))[!(surv[[7]] %in% 0 | is.na(surv[[7]]))]
+
eatsalm <- !(surv[[7]] %in% 0 | is.na(rowSums(surv[7:11])))
eatherr <- (1:nrow(surv))[surv[[12]] %in% 1 & !is.na(rowSums(surv[13:16]))]
+
eatherr <- surv[[12]] %in% 1 & !is.na(rowSums(surv[13:16]))
  
 
# Oletetaan, että covarianssimatriisi on vakio kaikille maille ja sukupuolille yms
 
# Oletetaan, että covarianssimatriisi on vakio kaikille maille ja sukupuolille yms
 
# mutta keskiarvo on spesifi näille ja kysymykselle.
 
# 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
+
#qlen <-  c(4,2,2,2,6,2,2,7,7,7,5,2,7,7,7,5) # Number of options in each question
 
+
# qlen not needed when dbinom is not used.
  
 
agel
 
agel
Line 287: Line 299:
 
genderl
 
genderl
 
fisl
 
fisl
 +
 +
####################### Descriptive statistics
 +
 +
oprint(cor(surv, use = "pairwise.complete.obs"))
 +
# --> Baltic salmon and herring eating are correlated, so they should be estimated together
  
 
############################# Plot original data
 
############################# Plot original data
  
levels(survey$Country)
+
## Eating frequencies of fish and Baltic salmon and herring with random noise, all
 +
pl <- surv[eatfish,c(5,8,10,13,15)]
 +
scatterplotMatrix(
 +
  data.matrix(pl) + runif(nrow(pl)*ncol(pl), -0.5, 0.5)
 +
)
  
 
ggplot(data.frame(
 
ggplot(data.frame(
Line 296: Line 317:
 
   legend = c("All", "Finland", "Sweden", "Denmark", "Estonia")
 
   legend = c("All", "Finland", "Sweden", "Denmark", "Estonia")
 
), aes(x=X, y=Y, label=legend))+
 
), aes(x=X, y=Y, label=legend))+
geom_text()+
+
  geom_text()+
 
   labs(title="Fish eating questions with random noise")
 
   labs(title="Fish eating questions with random noise")
  
Line 337: Line 358:
  
 
## Baltic salmon questions with some random noise
 
## Baltic salmon questions with some random noise
pl <- surv[eatsalm,7:10]
+
pl <- surv[eatsalm,8:11]
 
scatterplotMatrix(
 
scatterplotMatrix(
 
   data.matrix(pl) + runif(nrow(pl)*ncol(pl), -0.5, 0.5)
 
   data.matrix(pl) + runif(nrow(pl)*ncol(pl), -0.5, 0.5)
Line 350: Line 371:
 
   model{
 
   model{
 
     for(i in 1:S) {
 
     for(i in 1:S) {
       surv[i,1:4] ~ dmnorm(mu[], Omega[,])
+
       survs[i,1:4] ~ dmnorm(mus[], Omegas[,])
 
     }
 
     }
     mu[1:4] ~ dmnorm(mu0[1:4], S2[1:4,1:4])
+
     for(j in 1:H) {
     Omega[1:4,1:4] ~ dwish(S3[1:4,1:4],4)
+
      survh[j,1:4] ~ dmnorm(muh[], Omegah[,])
     ans.pred ~ dmnorm(mu[], Omega[,])
+
    }
 +
    mus[1:4] ~ dmnorm(mu0[1:4], S2[1:4,1:4])
 +
     Omegas[1:4,1:4] ~ dwish(S3[1:4,1:4],S)
 +
    anss.pred ~ dmnorm(mus[], Omegas[,])
 +
    muh[1:4] ~ dmnorm(mu0[1:4], S2[1:4,1:4])
 +
    Omegah[1:4,1:4] ~ dwish(S3[1:4,1:4],H)
 +
     ansh.pred ~ dmnorm(muh[], Omegah[,])
 
   }
 
   }
 
")
 
")
Line 361: Line 388:
 
   mod,
 
   mod,
 
   data = list(
 
   data = list(
     surv = surv[eatherr,13:16],
+
     survs = surv[eatsalm,c(8:11)],
     S = length(eatherr),
+
    S = sum(eatsalm),
     mu0 = rep(0.5,4),
+
    survh = surv[eatherr,c(13:16)],
 +
     H = sum(eatherr),
 +
     mu0 = rep(2,4),
 
     S2 = diag(4)/100000,
 
     S2 = diag(4)/100000,
 
     S3 = diag(4)/10000
 
     S3 = diag(4)/10000
Line 372: Line 401:
  
 
update(jags, 100)
 
update(jags, 100)
samps.j <- jags.samples(jags, c('mu','Omega', 'ans.pred'), 1000)
+
samps.j <- jags.samples(
j <- array(
+
  jags,  
   samps.j$ans.pred,
+
  c('muh','Omegah', 'ansh.pred', 'mus', 'Omegas', 'anss.pred'),  
 +
  1000
 +
)
 +
jh <- array(
 +
  samps.j$ansh.pred,
 +
  dim = c(4,1000,4),
 +
  dimnames = list(Question = 1:4, Iter = 1:1000, Seed = 1:4)
 +
)
 +
scatterplotMatrix(t(jh[,,1]))
 +
 
 +
js <- array(
 +
   samps.j$anss.pred,
 
   dim = c(4,1000,4),
 
   dim = c(4,1000,4),
 
   dimnames = list(Question = 1:4, Iter = 1:1000, Seed = 1:4)
 
   dimnames = list(Question = 1:4, Iter = 1:1000, Seed = 1:4)
 
)
 
)
scatterplotMatrix(t(j[,,1]))
+
scatterplotMatrix(t(js[,,1]))
samps.c <- coda.samples(jags, c('mu','Omega','z'), 1000)
+
 
 +
samps.c <- coda.samples(
 +
  jags,  
 +
  c('muh','Omegah', 'ansh.pred', 'mus', 'Omegas', 'anss.pred'),  
 +
  1000
 +
)
 
plot(samps.c)
 
plot(samps.c)
  
 +
jhm <- melt(jh[,,1], value.name = "Result")
 +
jsm <- melt(js[,,1], value.name = "Result")
 +
 +
oftenh  <- Ovariable("oftenh",  data = jsm[jsm$Question == 1, 2:3])
 +
muchh  <- Ovariable("muchh" ,  data = jsm[jsm$Question == 2, 2:3])
 +
ofsideh <- Ovariable("ofsideh", data = jsm[jsm$Question == 3, 2:3])
 +
musideh <- Ovariable("musideh", data = jsm[jsm$Question == 4, 2:3])
 +
oftens  <- Ovariable("oftens",  data = jhm[jsm$Question == 1, 2:3])
 +
muchs  <- Ovariable("muchs" ,  data = jhm[jsm$Question == 2, 2:3])
 +
ofsides <- Ovariable("ofsides", data = jhm[jsm$Question == 3, 2:3])
 +
musides <- Ovariable("musides", data = jhm[jsm$Question == 4, 2:3])
  
#objects.store(ans.pred, p.pred, p2.pred)
+
objects.store(oftenh, muchh, ofsideh, musideh, oftens, muchs, ofsides, musides)
#cat("Arrays ans.pred (answer), p.pred (probability to eat), p2.pred (p of answer) stored.\n")
+
cat("Ovariables oftenh, muchh, ofsideh, musideh, oftens, muchs, ofsides, musides stored.\n")
 
</rcode>
 
</rcode>
  

Revision as of 13:45, 29 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]
  • Model run 3.3.2017. p has more dimensions. [2]
  • Model run 25.3.2017. Several model versions: strange binomial+multivarnormal, binomial, fractalised multivarnormal [3]
  • Model run 27.3.2017 [4]
  • Other models except multivariate normal were archived and removed from active code 29.3.2017.
  • Model run 29.3.2017 with raw data graphs [5]
  • Model run 29.3.2017 with salmon and herring ovariables stored [6]

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