Difference between revisions of "POPs in Baltic herring"

From Testiwiki
Jump to: navigation, search
(Answer: updated for congener loop, needs still work)
(Arja's version 11.3.2016)
Line 8: Line 8:
 
== Answer  ==
 
== Answer  ==
  
POP concentrations in Baltic sea fish have been measured from samples collected in EU-kalat project.
+
== Rationale ==
 +
 
 +
POP concentrations in Baltic sea fish have been measured from samples collected in [[EU-kalat]] project.
  
 
<rcode graphics=1>
 
<rcode graphics=1>
Line 17: Line 19:
 
dat <- opbase.data("Op_en3104", subset = "POPs")
 
dat <- opbase.data("Op_en3104", subset = "POPs")
 
dat <- dat[dat$Fish_species == "Baltic herring" , ]
 
dat <- dat[dat$Fish_species == "Baltic herring" , ]
congeners = levels(dat$POP)
 
Y = length(congeners)
 
  
for (j in 1 : 3 ) { #only three rounds for testing
+
congeners = levels(dat$POP) #names of different congeners in data
   compdat <- dat[dat$POP == congeners[j] , ]
+
 
 +
Y = length(congeners) #number of congeners and j's in for loop
 +
 
 +
resultsall <-c('congener', 'meanorig', 'sdorig', 'meanlog', 'meanpost') #comined results table structure to store results of individual congener runs
 +
 
 +
 +
 
 +
for (j in 1 : 3 ) { # for testing reduced to 3 congeners, real loop amount is Y (=79)
 +
 
 +
   compdat <- dat[dat$POP == congeners[j] , ] #data for current congener
 +
 
 
   mo <- textConnection("model{
 
   mo <- textConnection("model{
 +
 
                     for( i in 1 : N ) {
 
                     for( i in 1 : N ) {
                     Compound[i] ~ dnorm(muOfLogCompound, tau2[i])
+
 
 +
                     Compound[i] ~ dnorm(muOfCompound, tau2[i])
 +
 
 
                     tau2[i] <- tau1*sqrt(n[i])
 
                     tau2[i] <- tau1*sqrt(n[i])
                     }                  
+
 
 +
                     }                
 +
 
 
                     tau1 ~ dunif(0.001, 1000)
 
                     tau1 ~ dunif(0.001, 1000)
                     muOfLogCompound ~ dnorm(0, 0.001)
+
 
                          }
+
                     muOfCompound ~ dnorm(0, 0.001)
 +
 
 +
                            }
 +
 
 
                     ")
 
                     ")
  
LogCompound <- log(compdat$result+1) #+1 because of negative log values
+
  shap <- shapiro.test(compdat$result) #test of normality
 +
 
 +
  #filename <- paste("shap", j, sep="") #save shapiro test result for each congener, just for fun
 +
 
 +
  #assign(filename, shap)
 +
 
 +
 
 +
 
 +
  if(shap$p.value < 0.05) { #if skewed, logtransformation, if not continue with original data. Or should the logtransformation be done in any case?
 +
 
 +
  Compound <- log(compdat$result+1) #+1 because of negative log values
 +
 
 +
  }
 +
  else Compound <- compdat$result
 +
  dataList = list(
 +
    Compound = Compound,
 +
    N = length(Compound),
 +
    n = compdat$N_individuals #number of fishes in sample
 +
  )
 +
 
 +
  jags <- jags.model(mo, data = dataList, n.chains = 4, n.adapt = 1000)
 +
 
 +
  close(mo)
  
dataList = list(
+
  update(jags, 1000)
    Compound = LogCompound,
+
  out <- coda.samples(jags, c('tau2', 'muOfCompound'), 500) # Stores a posterior sample
    N = length(LogCompound),
+
  plot(out)
    n = compdat$N_individuals
 
)
 
  
jags <- jags.model(mo, data = dataList, n.chains = 4, n.adapt = 1000)
+
  #filename <- paste("out", j, sep="") #save posterior for each congener
close(mo)
+
  #assign(filename, out)
update(jags, 1000)
 
  
out <- coda.samples(jags, c('tau1', 'muOfLogCompound'), 500) # Stores a posterior sample
+
  meanorig <- mean(compdat$result) #calculate mean for original data
plot(out)
+
  sdorig <- sd(compdat$result) #calcaulte sd of original data
filename <- paste("out", j, sep="")
+
  meanlog <- mean(Compound) #calculate mean for logdata
assign(filename, out)
+
  sdlog <- sd(Compound) #calculate sd for logdata
 +
  meanpost <- mean(data.frame(out[[4]])$muOfCompound) #calculate mean of mu for posterior (test 4)
 +
  #sdpost <- mean(data.frame(out[[4]])$tau2) #if needed, to be figured out how to do this
  
 +
  results <- data.frame(congeners[j], meanorig, sdorig, meanlog, meanpost) #results for congener
 +
 +
  resultsall <- rbind(resultsall, results[, 1:5]) #save results of congener to combined results table
 
}
 
}
  
Line 54: Line 96:
  
 
</rcode>
 
</rcode>
 
== Rationale  ==
 
  
 
== See also  ==
 
== See also  ==
Line 61: Line 101:
 
== References  ==
 
== References  ==
  
<br> <references />
+
<references />

Revision as of 09:42, 30 March 2016



Question

What are the concentrations of persistent organic pollutants (POPs) in Baltic sea fish.

Answer

Rationale

POP concentrations in Baltic sea fish have been measured from samples collected in EU-kalat project.

+ Show code

See also

References