Giter Club home page Giter Club logo

Comments (4)

tsostarics avatar tsostarics commented on June 12, 2024

Note that adding manual scores functionality would also require a change to the function that checks whether a contrast matrix was derived from contr.poly. So, that function would need the scores argument passed to it as well.

from contrastable.

tsostarics avatar tsostarics commented on June 12, 2024

Functionality for allowing empty parentheses in the formula syntax and additional arguments is available on the parens branch. Will be merged once I write more documentation. In general though, for a four level factor var in df:

enlist_contrasts(df, var ~ contr.poly)
enlist_contrasts(df, var ~ contr.poly())

Are now equivalent, eliminating the need to remove the () when using tab-autocomplete.

# assuming level names 1, 2, 3, 4
enlist_contrasts(df, var ~ scaled_sum_code)
enlist_contrasts(df, var ~ scaled_sum_code())
enlist_contrasts(df, var ~ scaled_sum_code + 1)
enlist_contrasts(df, var ~ scaled_sum_code() + 1)

Are also all equivalent.

my_scores <- c(.1, .2, .5, .7)
enlist_contrasts(df, var ~ contr.poly(scores = c(.1, .2, .5, .7)))
enlist_contrasts(df, var ~ contr.poly(c(.1, .2, .5, .7)))
enlist_contrasts(df, var ~ contr.poly(scores = my_scores))
enlist_contrasts(df, var ~ contr.poly(my_scores))

Are all equivalent, importantly allowing for scores to be manually specified by the user when using orthogonal polynomials. Note that the 2nd and 4th ones, which don't specify the argument name, only work because scores is the second positional argument (after n, which is auto-filled). I would recommend specifying the argument name though.

Errors:

enlist_contrasts(df, var ~ contr.poly(4)) will throw an error because the n argument is automatically supplied through the package's functionality, so specifying 4 will be set to the next positional argument, here scores.

enlist_contrasts(df, var ~ contr.poly(n=4)) will throw an error because n is specified twice (again because the package does it automatically). A more helpful error message will be written for this later.

enlist_contrasts(dv, var ~ contr.poly(bogus = 5)) will throw an error because bogus is an unused argument for contr.poly

glimpse_contrasts remains unchanged for the time being, and will likely become a separate enhancement issue.

from contrastable.

tsostarics avatar tsostarics commented on June 12, 2024

Not really an update but putting the current error messages for each example here for future reference when I update the errors:

enlist_contrasts(mtcars, gear ~ contr.poly(4))
Converting to factors: gear
Error in (function (n, scores = 1:n, contrasts = TRUE, sparse = FALSE)  : 
  'scores' argument is of the wrong length

Should make clear that n should not be specified in contrast-setting functions

enlist_contrasts(mtcars, gear ~ contr.poly(n=4))
Converting to factors: gear
Error in (function (n, scores = 1:n, contrasts = TRUE, sparse = FALSE)  : 
  formal argument "n" matched by multiple actual arguments

Should make clear that n should not be specified in contrast-setting functions

enlist_contrasts(mtcars, gear ~ contr.poly(bogus=4))
Converting to factors: gear
Error in (function (n, scores = 1:n, contrasts = TRUE, sparse = FALSE)  : 
  unused argument (bogus = 4)

actually this one can stay as is I think

# Gear has 3 levels
enlist_contrasts(mtcars, gear ~ contr.poly(scores = 2))
Converting to factors: gear
Error in (function (n, scores = 1:n, contrasts = TRUE, sparse = FALSE)  : 
  'scores' argument is of the wrong length

enlist_contrasts(mtcars, gear ~ contr.poly(scores = 1:2))
Converting to factors: gear
Error in (function (n, scores = 1:n, contrasts = TRUE, sparse = FALSE)  : 
  'scores' argument is of the wrong length

The fix is in the scores = 1:n part, but this can perhaps be made more clear by adding "length of scores should equal {length(levels(df$var))}"

from contrastable.

tsostarics avatar tsostarics commented on June 12, 2024

With some recent additions, namely to how functions and calls are handled, some of these aren't issues anymore. Really only this one is confusing/concerning:

enlist_contrasts(mtcars, gear ~ contr.poly(n=4))
Converting to factors: gear
Error in (function (n, scores = 1:n, contrasts = TRUE, sparse = FALSE)  : 
  formal argument "n" matched by multiple actual arguments

This should be addressed in .bundle_params. I'll fix this right now. The behavior here will be that n is replaced by the actual number of levels with a warning that this is happening. The situation this could occur in is if your analysis has a factor with 4 levels, then you filter a portion out and set the column to a factor not realizing you removed a level, leaving you with 3. If you have a set_contrasts later on that already has varName ~ foo(n=4) then we'll run into the situation here.

from contrastable.

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.