rasmusab / bayesian_first_aid

Inside every classical test there is a Bayesian model trying to get out.
326 stars 40 forks source link

JAGS - Unobserved node inconsistent with observed parents at initialization #3

Closed anmwinter closed 10 years ago

anmwinter commented 10 years ago

OSX 10.7.5 R 3.1 BayesianFirstAid 0.1 JAGS 3.3.0 for OS X

I am playing (err serious work) around with some data for my PhD candidacy exams. I am running this command:

fit_meta <- bayes.cor.test( ~ KS.OTUs + Boron, data = secNDmeta) Error in jags.model(textConnection(model_string), data = data, inits = inits, : Error in node sigma[1] Unobserved node inconsistent with observed parents at initialization

My data set looks like this (head version from R): Sorry the tab separated is screwy here:

 AD.OTUs KS.OTUs X16s.OTUs ActiveCarbon Aluminum Antimonies Arsenic Barium Beryllium

AZ03 2263 2098 1070 168.43 11.01 0.47 0.06 20.40 0.47 AZ04 1739 1011 655 -6.67 20.36 0.20 0.08 14.71 0.12 AZ05 1060 733 911 7.63 7.49 0.00 0.31 23.28 0.15 AZ06 1992 1839 1027 172.00 10.92 0.34 0.05 22.94 0.29 AZ10 5129 3035 794 68.37 16.75 0.33 0.16 17.65 0.18 AZ11 1269 1427 687 -22.74 12.38 0.00 0.06 41.28 0.06 Boron Cadmium Calcium Chromium Cobalt Copper Iron KMNO4 LOI Lead Lithium Magnesium AZ03 0.18 0.03 1687.48 0.00 0.02 0.29 0.73 0.51 2.91 0.28 0.11 298.06 AZ04 0.34 0.04 4545.20 0.00 0.00 1.08 0.26 0.53 0.95 0.09 0.14 157.88 AZ05 0.35 0.03 13526.16 0.02 0.03 0.33 0.80 0.53 2.50 0.08 0.19 148.07 AZ06 0.38 0.09 2718.54 0.00 0.01 0.47 0.43 0.51 2.53 0.36 0.07 163.69 AZ10 1.06 0.05 4283.93 0.01 0.01 0.87 0.50 0.52 1.25 0.36 0.35 510.39 AZ11 0.32 0.03 10311.61 0.00 0.01 0.26 0.73 0.53 0.78 0.24 0.09 155.72 Manganese Mercury Moisture Molybdenum Nickel Organic_Matter PMN Phosphorus Potassium AZ03 4.32 0 1.09 0.00 0.06 1.81 10.77 7.07 223.27 AZ04 2.02 0 0.98 0.00 0.03 0.44 1.10 15.17 368.55 AZ05 8.92 0 0.40 0.00 0.05 1.52 3.81 10.28 146.51 AZ06 6.80 0 1.13 0.01 0.04 1.54 6.65 18.27 321.66 AZ10 7.50 0 1.64 0.00 0.08 0.65 4.61 29.12 415.41 AZ11 79.75 0 0.98 0.01 0.02 0.31 0.23 11.28 227.11 Selenium Silicon Sodium Strontium Sulfur Thallium Vanadium Zinc pH Altitude..m. AZ03 0.02 29.76 438.70 10.39 4.05 0.04 0.01 0.72 6.73 1845.56 AZ04 0.00 41.78 500.13 12.51 8.19 0.03 0.01 0.25 8.31 1549.60 AZ05 0.00 17.51 1077.27 21.50 36.91 0.00 0.09 0.33 8.05 1536.19 AZ06 0.00 36.70 449.93 8.12 4.98 0.04 0.01 0.98 7.52 1472.49 AZ10 0.00 59.25 3232.91 25.01 70.45 0.02 0.02 0.26 8.07 1109.47 AZ11 0.00 18.60 610.42 0.00 11.33 0.00 0.00 0.33 8.41 1059.18 Latitude Longitude Geotype AZ03 34.21755 -109.2290 Desert AZ04 34.53717 -110.0940 Desert AZ05 34.56431 -110.3824 Desert AZ06 35.04198 -110.3869 Desert AZ10 34.39214 -111.4503 Desert AZ11 34.38891 -111.4580 Dry Forest

I did some quick google searching and found this error was common in older versions of JAGS but not in the new one. I ran another geochemical dataset using the same command early and had no problems.

I did find this: As a side note, it is helpful in JAGS to provide initial values for the incompletely observed occupancy state z that are consistent with observed presences, as provided in this example with zinit. In other words if x(j,i,t,k)=1, provide an intial value of 1 for z(j,i,t). Unlike WinBUGS and OpenBUGS, if you do not do this, you’ll often (but not always) encounter an error message

Over at http://mbjoseph.github.io/blog/2013/02/24/com_occ/

But that doesn't seem to be quite what is wrong here.

Do you have any suggestions? Thank you for your time and help!

ara

rasmusab commented 10 years ago

Would it be possible to temporarily share the full dataset with me? Then I could more easily look for the error. If this would be ok, you could perhaps mail it to rasmus.baath@gmail.com ?

rasmusab commented 10 years ago

Wow, that was a dangerous bug. I mixed up min and max which caused the initialization of the prior on SD to be completely off in cases where the scale of x and y differed a lot (like in your case). Fixed now. Thank you for reporting this!

(Just as a double check, could you rerun your analysis with the latest version?)

anmwinter commented 10 years ago

Yes, I will!!! Thank you for tracking that down.

ara

On Wed, Jun 11, 2014 at 3:11 AM, Rasmus Bååth notifications@github.com wrote:

Wow, that was a dangerous bug. I mixed up min and max which caused the initialization of the prior on SD to be completely off in cases where the scale of x and y differed a lot (like in your case). Fixed now. Thank you for reporting this!

(Just as a double check, could you rerun your analysis with the latest version?)

— Reply to this email directly or view it on GitHub https://github.com/rasmusab/bayesian_first_aid/issues/3#issuecomment-45718771 .

Quis hic locus, quae regio, quae mundi plaga. Ubi sum. Sub ortu solis an sub cardine glacialis ursae.

Impactstory AltMetrics https://impactstory.org/AraKooser Open Access Data and Figures http://figshare.com/authors/Ara%20Kooser/100048 Python, R code, and Data https://github.com/bioinfonm/2ndmeta