Comments (3)
To use resampling, you'll need to set up your workflow like this with the special formula
argument to add_model()
. One thing to keep in mind that your recipe is creating new features:
library(tidymodels)
#> Registered S3 method overwritten by 'tune':
#> method from
#> required_pkgs.model_spec parsnip
library(tidyverse)
testdf <- structure(list(RER = c(0.949, 0.929, 0.935, 0.89, 0.911, 0.85,
0.868, 0.85, 0.913, 0.969),
Time = c(30, 60, 120, 60, 70, 15,
74.711, 50, 140, 40),
Intensity = c(58, 72.6, 70, 68, 68.527,
60, 70, 45, 70, 70),
Study = c("Duhamel 2006", "Helge 1998",
"Van Zant 1997", "Parcell 1999", "Palmer 1999", "Lane 2015",
"Helge 1996", "Arkinstall 2004b", "Van Zant 1997", "Tarnopolsky 1995"
)), row.names = c(NA, -10L), class = c("tbl_df", "tbl", "data.frame"
)) %>% as.data.frame()
mixed_rec <-
recipe(RER ~ ., data = testdf) %>%
step_bs(Intensity)
prep(mixed_rec) %>% bake(new_data = NULL)
#> # A tibble: 10 × 6
#> Time Study RER Intensity_bs_1 Intensity_bs_2 Intensity_bs_3
#> <dbl> <fct> <dbl> <dbl> <dbl> <dbl>
#> 1 30 Duhamel 2006 0.949 0.395 0.352 0.104
#> 2 60 Helge 1998 0.929 0 0 1
#> 3 120 Van Zant 1997 0.935 0.0241 0.232 0.743
#> 4 60 Parcell 1999 0.89 0.0694 0.347 0.579
#> 5 70 Palmer 1999 0.911 0.0557 0.322 0.619
#> 6 15 Lane 2015 0.85 0.340 0.405 0.161
#> 7 74.7 Helge 1996 0.868 0.0241 0.232 0.743
#> 8 50 Arkinstall 2004b 0.85 0 0 0
#> 9 140 Van Zant 1997 0.913 0.0241 0.232 0.743
#> 10 40 Tarnopolsky 1995 0.969 0.0241 0.232 0.743
Created on 2021-11-09 by the reprex package (v2.0.1)
The special formula used by lmer will not know how to connect those to the original Intensity
:
library(tidymodels)
#> Registered S3 method overwritten by 'tune':
#> method from
#> required_pkgs.model_spec parsnip
library(tidyverse)
library(multilevelmod)
testdf <- structure(list(RER = c(0.949, 0.929, 0.935, 0.89, 0.911, 0.85,
0.868, 0.85, 0.913, 0.969),
Time = c(30, 60, 120, 60, 70, 15,
74.711, 50, 140, 40),
Intensity = c(58, 72.6, 70, 68, 68.527,
60, 70, 45, 70, 70),
Study = c("Duhamel 2006", "Helge 1998",
"Van Zant 1997", "Parcell 1999", "Palmer 1999", "Lane 2015",
"Helge 1996", "Arkinstall 2004b", "Van Zant 1997", "Tarnopolsky 1995"
)), row.names = c(NA, -10L), class = c("tbl_df", "tbl", "data.frame"
)) %>% as.data.frame()
mixed_model_spec <- linear_reg() %>% set_engine("lmer")
mixed_rec <- recipe(RER ~ ., data = testdf) %>%
step_bs(Intensity)
mixed_model_wf <- workflow() %>%
add_model(mixed_model_spec, formula = RER ~ Time + Intensity + (1 | Study)) %>%
add_recipe(mixed_rec)
fit(mixed_model_wf, testdf)
#> Error in eval(predvars, data, env): object 'Intensity' not found
#> Timing stopped at: 0.002 0 0.003
Created on 2021-11-09 by the reprex package (v2.0.1)
So you'll need to account for that. This is a limitation of using the formula
argument in a workflow; there's really no way to send in any flexible selectors. From workflows:
In those cases, a formula specifying the model structure must be passed unchanged into the model call itself.
from multilevelmod.
I believe this can work:
library(splines)
mixed_model_wf <- workflow() %>%
add_model(mixed_model_spec, formula = RER ~ Time + bs(Intensity) + (1 | Study)) %>%
add_recipe(mixed_rec)
from multilevelmod.
This issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org) and link to this issue.
from multilevelmod.
Related Issues (20)
- Installation of multilevelmod fails HOT 4
- Release multilevelmod 0.2.0 HOT 1
- bug in when using there is mismatch between number of labels in training and testing data set. HOT 4
- Require glmmLasso model HOT 2
- Release multilevelmod 1.0.0 HOT 1
- Incorrect predictions from fit_resamples() when applied to lmer model HOT 2
- New model request: gpboost Tree-Boosting with Gaussian Process and Mixed Effects Models HOT 3
- extracting parameter sets of MCMC iterations from `model_fit` object HOT 3
- New model request: glmmLasso HOT 1
- New model request: Mixed effect random forest (MERF) HOT 6
- Are multinom_reg() models supported? HOT 5
- Upkeep for multilevelmod 2023 HOT 1
- Use cli errors
- Default prediction mode for lmer - re.form = NA HOT 3
- Add issue templates HOT 1
- Use rlang type-checkers
- Combining Feature selection and mixed effects models: Error in eval(predvars, data, env): object ' ' not found HOT 4
- `logistic_reg(engine = "gee")` doesn't support dot in formula
- New Model Request: a spatial multilevel model HOT 1
- Linear Quantile Mixed Model (lqmm) 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 multilevelmod.