Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Account for tibble (non-)drop behavior in aoa #12

Open
gpatoine opened this issue Jan 19, 2021 · 0 comments
Open

Account for tibble (non-)drop behavior in aoa #12

gpatoine opened this issue Jan 19, 2021 · 0 comments

Comments

@gpatoine
Copy link

gpatoine commented Jan 19, 2021

First, thanks for your work on CAST. It is a very nice package and I am looking forward to further developments.

I recently ran into an issue while trying to run the tutorial https://cran.r-project.org/web/packages/CAST/vignettes/AOA-tutorial.html with my own data. I ran the function aoa, but the AOA$AOA results were only zeros.

AOA <- aoa(newdata = newdata, model = mod1, returnTrainDI = TRUE, cl = cl)

I found the issue was that I am using a tibble when training the model as below:

mod1 <- train(x = mytbl[,predictorNames], 
               y = mytbl$response,
               method = "rf",
               importance = TRUE,
               tuneGrid = expand.grid(mtry = c(2:length(predictorNames))),
               trControl = trainControl(method = "cv", savePredictions = TRUE))

Because of that, model$trainingData is also a tibble, and on line 168, newdata[,catvar] becomes NA, because I have one categorical predictor. tibble has a different dropping behavior than data.frame when a single column is returned. Specifically, unique(train[,catvar]) return a one-column tibble instead of a vector.

CAST/R/aoa.R

Line 168 in b34bc35

newdata[!newdata[,catvar]%in%unique(train[,catvar]),catvar] <- NA

The solution for me was to use mytbl <- as.data.frame(mytbl) before training the model, but I would suggest to use this at the beginning of the aoa function call to increase robustness to handle tibbles as well:

if(is.null(train)){train <- as.data.frame(model$trainingData)}

I don't have a ready reprex but I hope my description is sufficient to understand the issue.

HannaMeyer pushed a commit that referenced this issue Feb 7, 2024
* implement quantitative density layer

* document parameter k

* comments

* just spaces to be in sync with qmd scripts

* change QD to LPD

* update validation and maxLPD derivation

* update plot and print (#2)

* add exploreAOA function (#3)

* update plot and print

* add exploreAOA to package

* add message for trainLPD calculation

* Dev (#4)

* update plot and print

* add exploreAOA to package

* add message for trainLPD calculation

* update explore AOA docs

* shift package to description

* update exploreAOA docs

* update exploreAOA docs and add xmark

* update aoa, trainDI and exploreAOA docs

* update aoa docs

* change order of print.aoa

* update aoa.Rd

* update DESCRIPTION

* Dev (#6)

* update plot and print

* add exploreAOA to package

* add message for trainLPD calculation

* update explore AOA docs

* shift package to description

* update exploreAOA docs

* update exploreAOA docs and add xmark

* update aoa, trainDI and exploreAOA docs

* update aoa docs

* change order of print.aoa

* update aoa.Rd

* update DESCRIPTION

* update aoa & trainDI

* add trainDat upload options

* raster to terra and new layout (#5)

* update plot function

* update exploreAOA

* update exploreAOA

* fix error

* fix error

* fix crs bounding box issue

* rm commented code

* update plot.aoa & exploreAOA

* fix error in trainLPD calculation

* fix MD calculation

* fix order in print.aoa & message in aoa()

* add predictors tif to CAST package

* add countryboundaries

* add elevation

* Dev (#12)

* update plot and print

* add exploreAOA to package

* add message for trainLPD calculation

* update explore AOA docs

* shift package to description

* update exploreAOA docs

* update exploreAOA docs and add xmark

* update aoa, trainDI and exploreAOA docs

* update aoa docs

* change order of print.aoa

* update aoa.Rd

* update DESCRIPTION

* update aoa & trainDI

* add trainDat upload options

* raster to terra and new layout (#5)

* update plot function

* update exploreAOA

* update exploreAOA

* fix error

* fix error

* fix crs bounding box issue

* rm commented code

* update plot.aoa & exploreAOA

* fix error in trainLPD calculation

* fix MD calculation

* fix order in print.aoa & message in aoa()

* add predictors tif to CAST package

* add countryboundaries

* add elevation

* Change `maxLPD` parameter handling & enable `trainLPD` calculation with only training data provided (no model) (#7)

* add to maxLPD percantages

* update maxLPD parameter validation

* enable trainLPD calc with only trainDat (no model)

* minor change in maxLPD setting

* Add `LPDtoErrormetric` functionality (#8)

* add LPDtoErrormetric and adjust plot functions

* small change

* minor changes on docs and comments

* major docs update

* update DItoErrormetric and LPDtoErrormetric

* New calculation methods for LPD of training data and LPD of prediction data, add DI_LPDtoErrormetric  (#9)

* update trainLPD implementation in trainDI

* add DI_LPDtoErrormetric

* update docs

* update `toErrormetric` functions

* update `...toErrormetric` functions

* update CAST docs

* change legend position in exploreAOA

* update aoa and .knndist - enhance performance of LPD calculation

* update trainDI - add progress bars and messages

* update DI_LPDtoErrormetric & LPDtoErrormetric to enable multiCV

* Feat train di new (#11)

* Dev (#6)

* update plot and print

* add exploreAOA to package

* add message for trainLPD calculation

* update explore AOA docs

* shift package to description

* update exploreAOA docs

* update exploreAOA docs and add xmark

* update aoa, trainDI and exploreAOA docs

* update aoa docs

* change order of print.aoa

* update aoa.Rd

* update DESCRIPTION

* update aoa & trainDI

* add trainDat upload options

* raster to terra and new layout (#5)

* update plot function

* update exploreAOA

* update exploreAOA

* fix error

* fix error

* fix crs bounding box issue

* rm commented code

* update plot.aoa & exploreAOA

* fix error in trainLPD calculation

* fix MD calculation

* fix order in print.aoa & message in aoa()

* add predictors tif to CAST package

* add countryboundaries

* add elevation

* update trainLPD implementation in trainDI

* add DI_LPDtoErrormetric

* update docs

* update `toErrormetric` functions

* update `...toErrormetric` functions

* update CAST docs

* change legend position in exploreAOA

* update aoa and .knndist - enhance performance of LPD calculation

* update trainDI - add progress bars and messages

* update DI_LPDtoErrormetric & LPDtoErrormetric to enable multiCV

* fix error in LPDtoErrormetric

* Dev (#13)

* update plot and print

* add exploreAOA to package

* add message for trainLPD calculation

* update explore AOA docs

* shift package to description

* update exploreAOA docs

* update exploreAOA docs and add xmark

* update aoa, trainDI and exploreAOA docs

* update aoa docs

* change order of print.aoa

* update aoa.Rd

* update DESCRIPTION

* update aoa & trainDI

* add trainDat upload options

* raster to terra and new layout (#5)

* update plot function

* update exploreAOA

* update exploreAOA

* fix error

* fix error

* fix crs bounding box issue

* rm commented code

* update plot.aoa & exploreAOA

* fix error in trainLPD calculation

* fix MD calculation

* fix order in print.aoa & message in aoa()

* add predictors tif to CAST package

* add countryboundaries

* add elevation

* Change `maxLPD` parameter handling & enable `trainLPD` calculation with only training data provided (no model) (#7)

* add to maxLPD percantages

* update maxLPD parameter validation

* enable trainLPD calc with only trainDat (no model)

* minor change in maxLPD setting

* Add `LPDtoErrormetric` functionality (#8)

* add LPDtoErrormetric and adjust plot functions

* small change

* minor changes on docs and comments

* major docs update

* update DItoErrormetric and LPDtoErrormetric

* New calculation methods for LPD of training data and LPD of prediction data, add DI_LPDtoErrormetric  (#9)

* update trainLPD implementation in trainDI

* add DI_LPDtoErrormetric

* update docs

* update `toErrormetric` functions

* update `...toErrormetric` functions

* update CAST docs

* change legend position in exploreAOA

* update aoa and .knndist - enhance performance of LPD calculation

* update trainDI - add progress bars and messages

* update DI_LPDtoErrormetric & LPDtoErrormetric to enable multiCV

* Feat train di new (#11)

* Dev (#6)

* update plot and print

* add exploreAOA to package

* add message for trainLPD calculation

* update explore AOA docs

* shift package to description

* update exploreAOA docs

* update exploreAOA docs and add xmark

* update aoa, trainDI and exploreAOA docs

* update aoa docs

* change order of print.aoa

* update aoa.Rd

* update DESCRIPTION

* update aoa & trainDI

* add trainDat upload options

* raster to terra and new layout (#5)

* update plot function

* update exploreAOA

* update exploreAOA

* fix error

* fix error

* fix crs bounding box issue

* rm commented code

* update plot.aoa & exploreAOA

* fix error in trainLPD calculation

* fix MD calculation

* fix order in print.aoa & message in aoa()

* add predictors tif to CAST package

* add countryboundaries

* add elevation

* update trainLPD implementation in trainDI

* add DI_LPDtoErrormetric

* update docs

* update `toErrormetric` functions

* update `...toErrormetric` functions

* update CAST docs

* change legend position in exploreAOA

* update aoa and .knndist - enhance performance of LPD calculation

* update trainDI - add progress bars and messages

* update DI_LPDtoErrormetric & LPDtoErrormetric to enable multiCV

* fix error in LPDtoErrormetric

* masking order

* adapt default degrees of freedom

* add exp and scam exp errormodels

* update docs

* update docs

* Dev (#14)

* update plot and print

* add exploreAOA to package

* add message for trainLPD calculation

* update explore AOA docs

* shift package to description

* update exploreAOA docs

* update exploreAOA docs and add xmark

* update aoa, trainDI and exploreAOA docs

* update aoa docs

* change order of print.aoa

* update aoa.Rd

* update DESCRIPTION

* update aoa & trainDI

* add trainDat upload options

* raster to terra and new layout (#5)

* update plot function

* update exploreAOA

* update exploreAOA

* fix error

* fix error

* fix crs bounding box issue

* rm commented code

* update plot.aoa & exploreAOA

* fix error in trainLPD calculation

* fix MD calculation

* fix order in print.aoa & message in aoa()

* add predictors tif to CAST package

* add countryboundaries

* add elevation

* Change `maxLPD` parameter handling & enable `trainLPD` calculation with only training data provided (no model) (#7)

* add to maxLPD percantages

* update maxLPD parameter validation

* enable trainLPD calc with only trainDat (no model)

* minor change in maxLPD setting

* Add `LPDtoErrormetric` functionality (#8)

* add LPDtoErrormetric and adjust plot functions

* small change

* minor changes on docs and comments

* major docs update

* update DItoErrormetric and LPDtoErrormetric

* New calculation methods for LPD of training data and LPD of prediction data, add DI_LPDtoErrormetric  (#9)

* update trainLPD implementation in trainDI

* add DI_LPDtoErrormetric

* update docs

* update `toErrormetric` functions

* update `...toErrormetric` functions

* update CAST docs

* change legend position in exploreAOA

* update aoa and .knndist - enhance performance of LPD calculation

* update trainDI - add progress bars and messages

* update DI_LPDtoErrormetric & LPDtoErrormetric to enable multiCV

* Feat train di new (#11)

* Dev (#6)

* update plot and print

* add exploreAOA to package

* add message for trainLPD calculation

* update explore AOA docs

* shift package to description

* update exploreAOA docs

* update exploreAOA docs and add xmark

* update aoa, trainDI and exploreAOA docs

* update aoa docs

* change order of print.aoa

* update aoa.Rd

* update DESCRIPTION

* update aoa & trainDI

* add trainDat upload options

* raster to terra and new layout (#5)

* update plot function

* update exploreAOA

* update exploreAOA

* fix error

* fix error

* fix crs bounding box issue

* rm commented code

* update plot.aoa & exploreAOA

* fix error in trainLPD calculation

* fix MD calculation

* fix order in print.aoa & message in aoa()

* add predictors tif to CAST package

* add countryboundaries

* add elevation

* update trainLPD implementation in trainDI

* add DI_LPDtoErrormetric

* update docs

* update `toErrormetric` functions

* update `...toErrormetric` functions

* update CAST docs

* change legend position in exploreAOA

* update aoa and .knndist - enhance performance of LPD calculation

* update trainDI - add progress bars and messages

* update DI_LPDtoErrormetric & LPDtoErrormetric to enable multiCV

* fix error in LPDtoErrormetric

* masking order

* adapt default degrees of freedom

* add exp and scam exp errormodels

* update docs

* update docs

* Dev (#15)

* update plot and print

* add exploreAOA to package

* add message for trainLPD calculation

* update explore AOA docs

* shift package to description

* update exploreAOA docs

* update exploreAOA docs and add xmark

* update aoa, trainDI and exploreAOA docs

* update aoa docs

* change order of print.aoa

* update aoa.Rd

* update DESCRIPTION

* update aoa & trainDI

* add trainDat upload options

* raster to terra and new layout (#5)

* update plot function

* update exploreAOA

* update exploreAOA

* fix error

* fix error

* fix crs bounding box issue

* rm commented code

* update plot.aoa & exploreAOA

* fix error in trainLPD calculation

* fix MD calculation

* fix order in print.aoa & message in aoa()

* add predictors tif to CAST package

* add countryboundaries

* add elevation

* Change `maxLPD` parameter handling & enable `trainLPD` calculation with only training data provided (no model) (#7)

* add to maxLPD percantages

* update maxLPD parameter validation

* enable trainLPD calc with only trainDat (no model)

* minor change in maxLPD setting

* Add `LPDtoErrormetric` functionality (#8)

* add LPDtoErrormetric and adjust plot functions

* small change

* minor changes on docs and comments

* major docs update

* update DItoErrormetric and LPDtoErrormetric

* New calculation methods for LPD of training data and LPD of prediction data, add DI_LPDtoErrormetric  (#9)

* update trainLPD implementation in trainDI

* add DI_LPDtoErrormetric

* update docs

* update `toErrormetric` functions

* update `...toErrormetric` functions

* update CAST docs

* change legend position in exploreAOA

* update aoa and .knndist - enhance performance of LPD calculation

* update trainDI - add progress bars and messages

* update DI_LPDtoErrormetric & LPDtoErrormetric to enable multiCV

* Feat train di new (#11)

* Dev (#6)

* update plot and print

* add exploreAOA to package

* add message for trainLPD calculation

* update explore AOA docs

* shift package to description

* update exploreAOA docs

* update exploreAOA docs and add xmark

* update aoa, trainDI and exploreAOA docs

* update aoa docs

* change order of print.aoa

* update aoa.Rd

* update DESCRIPTION

* update aoa & trainDI

* add trainDat upload options

* raster to terra and new layout (#5)

* update plot function

* update exploreAOA

* update exploreAOA

* fix error

* fix error

* fix crs bounding box issue

* rm commented code

* update plot.aoa & exploreAOA

* fix error in trainLPD calculation

* fix MD calculation

* fix order in print.aoa & message in aoa()

* add predictors tif to CAST package

* add countryboundaries

* add elevation

* update trainLPD implementation in trainDI

* add DI_LPDtoErrormetric

* update docs

* update `toErrormetric` functions

* update `...toErrormetric` functions

* update CAST docs

* change legend position in exploreAOA

* update aoa and .knndist - enhance performance of LPD calculation

* update trainDI - add progress bars and messages

* update DI_LPDtoErrormetric & LPDtoErrormetric to enable multiCV

* fix error in LPDtoErrormetric

* masking order

* adapt default degrees of freedom

* add exp and scam exp errormodels

* update docs

* update docs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant