Coder Social home page Coder Social logo

Code quit working about hmsc HOT 5 OPEN

morgan-j-black avatar morgan-j-black commented on July 17, 2024
Code quit working

from hmsc.

Comments (5)

jarioksa avatar jarioksa commented on July 17, 2024

Again a tibble! That tibble brings so much pain.

Variables Richness, Complexity and Dist.Refuge are not variables, but they are matrices. Please change them to variables (vectors). Currently their dimensions are given as [46, 1], but it should only read Richness: num -1.935, -0.935... without those dimensions.

See issue #65 which is a duplicate of this.

from hmsc.

morgan-j-black avatar morgan-j-black commented on July 17, 2024

from hmsc.

morgan-j-black avatar morgan-j-black commented on July 17, 2024

Just a quick follow up... in this instance, the matrices that should have been vectors were generated using the scale function in base r. I had been avoiding the use of tibbles as I know they can be problematic in general.

dat$Richness = scale(dat$richAll) # this code created the matrices in the dataframe.

from hmsc.

brendanf avatar brendanf commented on July 17, 2024

@morgan-j-black You are right, base scale() always returns a matrix, even if its argument is a vector, and matrix columns are allowed in base data.frames. Single-column matrices are converted to a vector by the data.frame() constructor function, but this does not happen when they are assigned into an existing data.frame. Try dat$Richness = c(scale(dat$richAll)) to remove the dimension attribute.

(As an aside, as recently as 2018, tibble was more restrictive than base data.frame, and did not allow matrix columns by assignment.)

from hmsc.

jarioksa avatar jarioksa commented on July 17, 2024

I too hastily put the blame on tibble where we have seen this problem earlier. Actually, it is possible to have even more pathological data frames, such as with poly(x, 2) which adds one variable that is a two-column matrix.

We (or probably I) added the test against matrix entries after issue #65. The basic Hmsc and sampleMcmc commands accept data frames with matrix entries, but then some posterior analysis tools fail for reasons that were outside the Hmsc package (that is, we called functions in other packages such as base and stats and these failed). So we considered it is better to catch these cases before sampleMcmc run, and not weeks later when you finished with sampling and tried to do something with the result. The change was quick and dirty. The minimum is that we need to improve error reporting. I don't have an instant idea to automatically remove the matrix entries from the data frames stored in the result object. This really concerns those auxiliary methods that need access to the original data frame (most of analytic Hmsc tools do not need data frame but they only operate on model matrix which is OK with matrix variables).

from hmsc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.