Difference between revisions of "POPs in Baltic herring"

From Testiwiki
Jump to: navigation, search
m (Rationale: fixed the resultsall posterior calculation precision to SD)
m (Rationale: code updated)
Line 19: 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" , ]
 +
 +
dat <- subset(dat,!(is.na(dat["Result"])))
 +
dat <- dropall(dat)
  
 
congeners <- levels(dat$POP) #names of different congeners in data
 
congeners <- levels(dat$POP) #names of different congeners in data
Line 24: Line 27:
 
Y <- length(congeners) #number of congeners and j's in for loop
 
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
+
compdat <- dat[dat$POP %in% congeners[1:Y] , ] #data for current congener
 
+
Compound <- log10(compdat$Result+1E-2) #+1E-2 because zero concentrations are not allowed
compdat <- dat[dat$POP %in% congeners[1:3] , ] #data for current congener
 
Compound <- log(compdat$Result+1E-2) #+1E-2 because zero concentrations are not allowed
 
  
 
mo <- textConnection("model{
 
mo <- textConnection("model{
    for (j in 1 : 3 ) { # for testing reduced to 3 congeners, real loop amount is Y (=79)
+
                    for (j in 1 : Y ) {
      tau1[j] ~ dunif(0.001, 1000)
+
                    tau1[j] ~ dunif(0.001, 1000)
      muOfCompound[j] ~ dnorm(0, 0.001)
+
                    muOfCompound[j] ~ dnorm(0, 0.001)
    }
+
                    }
    for( i in 1 : N ) {
+
                    for( i in 1 : N ) {
      Compound[i] ~ dnorm(muOfCompound[POP[i]], tau2[i])
+
                    Compound[i] ~ dnorm(muOfCompound[POP[i]], tau2[i])
      tau2[i] <- tau1[POP[i]]*sqrt(n[i])
+
                    tau2[i] <- tau1[POP[i]]*sqrt(n[i])
    }
+
                    }
  }
+
                    }
")
+
                    ")
 
 
#  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+1E-2) #+1E-2 because zero concentrations are not allowed
 
#  } else {
 
#    Compound <- compdat$Result
 
#  }
 
 
 
 
dataList = list(
 
dataList = list(
 +
  Y = Y,
 
   Compound = Compound,
 
   Compound = Compound,
 
   POP = as.numeric(compdat$POP),
 
   POP = as.numeric(compdat$POP),
Line 69: Line 57:
 
plot(out)
 
plot(out)
  
#filename <- paste("out", j, sep="") #save posterior for each congener
+
Meanlogpost = c()
#assign(filename, out)
+
for (j in 1 : Y) {
 +
  logmean <- mean(out[[4]][,j]) #calculate mean of logmu for posterior (test 4)
 +
  Meanlogpost = c(Meanlogpost, logmean)
 +
}
  
 +
Sdlogpost = c()
 +
for (j in 1 : Y) {
 +
  logsd <- sqrt(1/(mean(out[[4]][,j+Y])))
 +
  Sdlogpost = c(Sdlogpost, logsd)
 +
}
 +
 +
Meanpost = c()
 +
for (j in 1 : Y) {
 +
  mu  = out[[4]][,j]
 +
  mean <- mean(10^mu)-1E-2 #calculate mean of mu for posterior (test 4)
 +
  Meanpost = c(Meanpost, mean)
 +
}
  
 
resultsall <- data.frame(
 
resultsall <- data.frame(
Line 78: Line 81:
 
   Meanlog = aggregate(Compound, compdat["POP"], mean)$x, #calculate mean for logdata
 
   Meanlog = aggregate(Compound, compdat["POP"], mean)$x, #calculate mean for logdata
 
   Sdlog = aggregate(Compound, compdat["POP"], sd)$x, #calculate sd for logdata
 
   Sdlog = aggregate(Compound, compdat["POP"], sd)$x, #calculate sd for logdata
   Meanpost = c(mean((out[[4]])[,1]), #calculate mean of mu for posterior (test 4)
+
   Meanlogpost = Meanlogpost,
              mean((out[[4]])[,2]),
+
  Sdlogpost = Sdlogpost,
              mean((out[[4]])[,3])
+
  Meanpost = 10^Meanlogpost-1E-02,
    ),
+
  Sdpost = 10^Sdlogpost-1E-02
    Sdpost = c(sqrt(1/(mean((out[[4]])[,4]))), #calculate mean of mu for posterior (test 4)
+
  )
                sqrt(1/(mean((out[[4]])[,5]))),
 
                sqrt(1/(mean((out[[4]])[,6])))
 
    )
 
)
 
  
 
oprint(resultsall)
 
oprint(resultsall)

Revision as of 11:23, 8 June 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