hmsc-r / HMSC

GNU General Public License v3.0
102 stars 37 forks source link

Specification of fixed and random effects in hmsc 3.0.4 #39

Open AdMePo opened 4 years ago

AdMePo commented 4 years ago

Hi,

First of all, thank you very much for developping the Hmscpackage in R, and for the very clear papers and vignettes about this very interesting and useful framework.

I'm reporting the following error that popped up while I was estimating a model with a handfull of random effects, while the model was working fine without them:

[1] "Setting updater$Gamma2=FALSE due to specified phylogeny matrix"
[1] "Computing chain 1"
Error in Eta[[r]][hM$Pi[, r], ] : out of range index

Here is the traceback():

3: computeInitialParameters(hM, initPar)
2: sampleChain(chain)
1: sampleMcmc(m4, thin = thin, samples = samples, transient = transient, 
       nChains = nChains, verbose = verbose)

I would appreciate some help and feedback to figure out what is happening. One part of my struggle comes from deciding which categorical predictors to treat as random or fixed effects, and the other about how to specify these in the models. Reading the issue "Specification of random effects for nested+longitudinal study design #32" did not helped. I provide some context below.

I'm intending to use Hmscto study microbial communities. I'm currently working on a reduced set of 50 species (YData) to get some experience with Hmsc and figure out a script that works fine (typically, I could work with up to 10,000 species). I have environmental (XData) and phylogenetic correlation (CData) data in hands, trait data (TData) will come later.

Thanks for reading this post. Feel free to ask more details if needed, I'll be happy to provide them.

Adrien

ovaskain commented 4 years ago

Hi,

There is probably something wrong how the random effects are set up to. Just a quick comment. When you define:

rL0 = HmscRandomLevel(units = studyDesign$Site)

||and then ...("Site" = rL0, ...)||

it is maybe safer to define

|rL0| = |||HmscRandomLevel(units = levels(studyDesign$Site))|||

|||If this does not solve the error message, we should look in more detail how you defined the model object.|||

Otso

On 29.1.2020 13.42, AdMePo wrote:

Hi,

First of all, thank you very much for developping the |Hmsc |package in |R|, and for the very clear papers and vignettes about this very interesting and useful framework.

I'm reporting the following error that popped up while I was estimating a model with a handfull of random effects, while the model was working fine without them:

|[1] "Setting updater$Gamma2=FALSE due to specified phylogeny matrix" [1] "Computing chain 1" Error in Eta[[r]][hM$Pi[, r], ] : out of range index |

Here is the |traceback()|:

|3: computeInitialParameters(hM, initPar) 2: sampleChain(chain) 1: sampleMcmc(m4, thin = thin, samples = samples, transient = transient, nChains = nChains, verbose = verbose) |

I would appreciate some help and feedback to figure out what is happening. One part of my struggle comes from deciding which categorical predictors to treat as random or fixed effects, and the other about how to specify these in the models. Reading the issue "Specification of random effects for nested+longitudinal study design

32 https://github.com/hmsc-r/HMSC/issues/32" did not helped. I

provide some context below.

I'm intending to use |Hmsc |to study microbial communities. I'm currently working on a reduced set of 50 species (|YData|) to get some experience with Hmsc and figure out a script that works fine (typically, I could work with up to 10,000 species). I have environmental (|XData|) and phylogenetic correlation (|CData|) data in hands, trait data (|TData|) will come later.

*

The 108 sampling units have a unique |sample.id| that can be
grouped in the following sets of observations: 3 |Replicates |X 2
|Fractions |X 3 |Compartments |X 6 |Sites|. Because I expect these
sets share a common property, I would be inclined to treat them
all as random effects. I am rigth? What about the |Sample.id|?

*

I've defined each |rL| with |HmscRandomLevel()|, /e.g./ for the
effect of Site |HmscRandomLevel(units = studyDesign$Site)|. Then I
specified |ranLevels = list("Site" = rL0, "Compartment" = rL1,
"Fraction" = rL2, "Replicate" = rL3, "Sample.id" = rL4)| in my
model. Is that right or I am missing something?

Thanks for reading this post. Feel free to ask more details if needed, I'll be happy to provide them.

Adrien

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/hmsc-r/HMSC/issues/39?email_source=notifications&email_token=AEIYMZUAI7NYRENGUBGV3PTRAFTRRA5CNFSM4KNDFEIKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4IJQG6DQ, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEIYMZQ45LBI6DX3CD42BKTRAFTRRANCNFSM4KNDFEIA.

AdMePo commented 4 years ago

Hi, There is probably something wrong how the random effects are set up to. Just a quick comment. When you define: |rL0 = HmscRandomLevel(units = studyDesign$Site)| || ||and then ...("Site" = rL0, ...)|| ||it is maybe safer to define || |rL0| = |||HmscRandomLevel(units = levels(studyDesign$Site))||| |||If this does not solve the error message, we should look in more detail how you defined the model object.||| |||Otso |||

Hi Otso and thanks for your reply,

I tried to define random levels as you suggested. The code did run well in test.mode with random effects 'Site', 'Compartment', 'Fraction' and 'Replicate'.

However, I got the same error as above (Error in Eta[[r]][hM$Pi[, r], ]) when I added the random effect at the Sample.id (thiner) level, whether it was defining it like HmscRandomLevel(units = unique(studyDesign$Sample.id)or HmscRandomLevel(units = levels(studyDesign$Sample.id) or HmscRandomLevel(units = studyDesign$Sample.id).

Thus I'm making some progress getting there, but not yet done.

Adrien

ovaskain commented 4 years ago

Hi Adrien,

If you still have the problem, can you email me the data and script so that I can reproduce the error and try to figure out what is wrong?

Best,

Otso

On 29.1.2020 16.09, AdMePo wrote:

Hi, There is probably something wrong how the random effects are
set up to. Just a quick comment. When you define: |rL0 =
HmscRandomLevel(units = studyDesign$Site)| || ||and then
...("Site" = rL0, ...)|| ||it is maybe safer to define || |rL0| =
|||HmscRandomLevel(units = levels(studyDesign$Site))||| |||If this
does not solve the error message, we should look in more detail
how you defined the model object.||| |||Otso |||

Hi Otso and thanks for your reply,

I tried to define random levels as you suggested. The code did run well in test.mode with random effects 'Site', 'Compartment', 'Fraction' and 'Replicate'.

However, I got the same error as above (|Error in Eta[[r]][hM$Pi[, r], ]|) when I added the random effect at the Sample.id (thiner) level, whether it was defining it like |HmscRandomLevel(units = unique(studyDesign$Sample.id) |or |HmscRandomLevel(units = levels(studyDesign$Sample.id)| or |HmscRandomLevel(units = studyDesign$Sample.id)|.

Thus I'm making some progress getting there, but not yet done.

Adrien

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/hmsc-r/HMSC/issues/39?email_source=notifications&email_token=AEIYMZTJBQIXYRJSTP6N6LTRAGEYRA5CNFSM4KNDFEIKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEKHJ2EY#issuecomment-579771667, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEIYMZVRN7XLV3G3AHTJYGTRAGEYRANCNFSM4KNDFEIA.

AdMePo commented 4 years ago

Hi Otso,

Thanks for your offer. I'll send you my script and a representative extract of the data soon. I'm currently focusing on applications for tenure positions with deadlines around mid-March.

Best,

Adrien

Le dim. 9 févr. 2020 à 15:19, ovaskain notifications@github.com a écrit :

Hi Adrien,

If you still have the problem, can you email me the data and script so that I can reproduce the error and try to figure out what is wrong?

Best,

Otso

On 29.1.2020 16.09, AdMePo wrote:

Hi, There is probably something wrong how the random effects are set up to. Just a quick comment. When you define: |rL0 = HmscRandomLevel(units = studyDesign$Site)| || ||and then ...("Site" = rL0, ...)|| ||it is maybe safer to define || |rL0| = |||HmscRandomLevel(units = levels(studyDesign$Site))||| |||If this does not solve the error message, we should look in more detail how you defined the model object.||| |||Otso |||

Hi Otso and thanks for your reply,

I tried to define random levels as you suggested. The code did run well in test.mode with random effects 'Site', 'Compartment', 'Fraction' and 'Replicate'.

However, I got the same error as above (|Error in Eta[[r]][hM$Pi[, r], ]|) when I added the random effect at the Sample.id (thiner) level, whether it was defining it like |HmscRandomLevel(units = unique(studyDesign$Sample.id) |or |HmscRandomLevel(units = levels(studyDesign$Sample.id)| or |HmscRandomLevel(units = studyDesign$Sample.id)|.

Thus I'm making some progress getting there, but not yet done.

Adrien

— You are receiving this because you commented. Reply to this email directly, view it on GitHub < https://github.com/hmsc-r/HMSC/issues/39?email_source=notifications&email_token=AEIYMZTJBQIXYRJSTP6N6LTRAGEYRA5CNFSM4KNDFEIKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEKHJ2EY#issuecomment-579771667>,

or unsubscribe < https://github.com/notifications/unsubscribe-auth/AEIYMZVRN7XLV3G3AHTJYGTRAGEYRANCNFSM4KNDFEIA .

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/hmsc-r/HMSC/issues/39?email_source=notifications&email_token=AONASI4GZZXCGAVRNRWCRJTRCAGGHA5CNFSM4KNDFEIKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOELGNUJQ#issuecomment-583850534, or unsubscribe https://github.com/notifications/unsubscribe-auth/AONASI5QJIHAVKYEKHU53WTRCAGGHANCNFSM4KNDFEIA .