Difference between revisions of "POPs in Baltic herring"
From Testiwiki
(→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" , ] | ||
− | |||
− | |||
− | for (j in 1 : 3 ) { # | + | 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( | + | |
+ | 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) | ||
− | + | ||
− | + | muOfCompound ~ dnorm(0, 0.001) | |
+ | |||
+ | } | ||
+ | |||
") | ") | ||
− | + | 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) | ||
− | + | update(jags, 1000) | |
− | + | out <- coda.samples(jags, c('tau2', 'muOfCompound'), 500) # Stores a posterior sample | |
− | + | plot(out) | |
− | |||
− | ) | ||
− | + | #filename <- paste("out", j, sep="") #save posterior for each congener | |
− | + | #assign(filename, out) | |
− | |||
− | + | meanorig <- mean(compdat$result) #calculate mean for original data | |
− | + | sdorig <- sd(compdat$result) #calcaulte sd of original data | |
− | + | meanlog <- mean(Compound) #calculate mean for logdata | |
− | + | 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> | ||
− | |||
− | |||
== See also == | == See also == | ||
Line 61: | Line 101: | ||
== References == | == References == | ||
− | + | <references /> |
Revision as of 09:42, 30 March 2016
This page is a variable.
The page identifier is Op_en2583 |
---|
Moderator:Nobody (see all) Click here to sign up. |
Give your opinion to the peer rating of the content of this page. |
Upload data
|
Contents
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.