Questions tagged [modelr]

modelr is an R package by Hadley Wickham designed to allow common operations with models to be piped. It is part of the larger tidyverse group of packages.

modelr is an R package by Hadley Wickham designed to allow common operations with models to be piped. It is part of the larger tidyverse group of packages.

28 questions
1
vote
1 answer

How do I add more model predictions after using gather_predictions()?

I used gather_predictions() to add several predictions to my data frame. Later on, perhaps after doing some visualizations, I want to add a new model's predictions. I can't seem to figure out how to do this. I tried using add_predictions() and…
Robin
  • 119
  • 2
  • 8
1
vote
2 answers

Expand one column in a tibble and have the descriptive columns follow

I want to use zoo::na.approx (but not married to this function) to fill in a response variable for the missing days in my dataframe. I'm having a tough time figuring out how to add the NAs to the original dataframe so that na.approx can fill them…
Nazer
  • 3,654
  • 8
  • 33
  • 47
1
vote
1 answer

k fold cross validation in purrr and model

I came across this example library(mtcars) set.seed(17) cv.error.10 = rep(0,10) for (i in 1:10){ glm.fit = glm(mpg∼poly(horsepower ,i),data=Auto) cv.error.10[i] = cv.glm(Auto,glm.fit,K=10)$delta[1] } cv.error.10 [1] 24.21 19.19 19.31 19.34…
Alex
  • 2,603
  • 4
  • 40
  • 73
1
vote
1 answer

modelr::bootstrap or broom::bootstrap and grouping problems

I have one long dataset that is composed of several datasets resulting from multiple imputations (let's say 10 imputations). They have an id variable identifying the imputation. On each of these imputed datasets I would like to bootstrap 10…
RNB
  • 457
  • 1
  • 5
  • 14
0
votes
1 answer

Bootstrapped standard errors and p-value from weighted mann-whitney test

I would like to bootstrap the p-value and standard errors from weighted Mann-Whitney U test. I can run the test as: weighted_mannwhitney(c12hour ~ c161sex + weight, efc) which works fine, but am not entirely sure how I can run a bootstrapped version…
microbe
  • 74
  • 6
0
votes
0 answers

modelr add_predictions error: in model.frame.default(Terms, newdata, na.action = na.action, xlev = object$xlevels)

I am facing the following error using modelr add_predictions function. modelr add_predictions error: in model.frame.default(Terms, newdata, na.action = na.action, xlev = object$xlevels): fe.lead.surgeon has new levels .... In my understanding, it is…
J.K.
  • 325
  • 2
  • 8
0
votes
0 answers

Add predictions using models with interactions in R

I am using modelr for adding predictions based on a linear regression model with interactions. The question is does add_predictions() work with interactions? df <- tibble::tibble( x1 = sort(runif(100)), x2 = sort(runif(100)), y = 2*x1 +…
Rtist
  • 3,825
  • 2
  • 31
  • 40
0
votes
2 answers

Select and apply correct model from different data frame using purrr

In my data, I have correlated data (diet and liver) for 50+ different compounds (simplified here). library(tidyverse) Sigma <- matrix(.7, nrow=6, ncol=6) + diag(6)*.3 vars_tr <- data.frame(MASS::mvrnorm(n=10, mu=c(2:7), Sigma=Sigma)) tr<-tibble( …
aleoconn
  • 57
  • 8
0
votes
1 answer

run model for each line of model parameters (meta) data.frame

In the spirit of purr, broom, modelr, I am trying to create a "meta" data.frame in which each row denotes the dataset (d) and the model parameters (yvar, xvars, FEvars). For instance: iris2 <- iris %>% mutate(Sepal.Length=Sepal.Length^2) meta <-…
LucasMation
  • 2,408
  • 2
  • 22
  • 45
0
votes
2 answers

Mapping a model to a permuted data set sometimes returns the model equation, rather than model output

I am trying to use the permute function in modelr with purrr map to calculate the mean values of two categories of data under permutation. The function behaves as one would expect if I am trying to calculate linear models off of the permuted data…
ohnoplus
  • 1,205
  • 1
  • 17
  • 29
0
votes
1 answer

Calculate all possible interactions in model_matrix

I'm simulating data with a fluctuating number of variables. As part of the situation, I am needing to calculate a model matrix with all possible combinations. See the following reprex for an example. I am able to get all two-interactions by…
Jake Thompson
  • 2,591
  • 1
  • 16
  • 32
0
votes
1 answer

Access the estimate inside a model object in R

I am running a simulation and would like to know if there was a way to access the "x" estimate inside of my model using broom, dplyr, modelr, or purrr. This gives me exactly what I want, but I don't want to use [[1]] in the last chunk of…
Alex
  • 2,603
  • 4
  • 40
  • 73
0
votes
1 answer

Group data by rep, fit model, and integrate curve

I have a series of points over time and I want to fit a curve to these points and then find the area under the curve. I can do it like this: fit<-loess(mass ~ hour, df) f <- function(x) predict(fit,newdata=x) answer<-integrate(f, 0, 60)$value So…
Nazer
  • 3,654
  • 8
  • 33
  • 47
1
2