Comments (4)
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.
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.
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.
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)
- Evaluating reference level as NA for `contr.helmert` HOT 5
- Add `{hypr}` integration HOT 2
- additional formula operator for labels HOT 2
- `contr.orthonorm` is transposed
- Error when applying contrasts to grouping variable in `grouped_df` HOT 1
- Add helper function to print fractional contrast matrices
- Improve error message for invalid reference level
- Change some function names HOT 1
- Pass `n_levels` to first function parameter
- Rename contrast scheme parameters from `n_levels` to `n`
- Redo formula handling for well-formedness checks HOT 4
- Allow multiple variable names or tidyselect helpers on left hand side of formulas
- Add warning when there are no dimnames when using `as_is` HOT 2
- Change default columns in glimpse_contrasts HOT 1
- Add how to use/cite in publication vignette/section of readme
- Add dataframe attribute for how contrasts are set
- Decompose interactions with `decompose_contrasts`
- Swap helmert coding to match order in contr.helmert
- Better error message when model data is not provided HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from contrastable.