Skip to content

Instantly share code, notes, and snippets.

@drsimonj
Last active June 6, 2017 01:46
Show Gist options
  • Select an option

  • Save drsimonj/5b2cfc428fce350676db5dc77c059052 to your computer and use it in GitHub Desktop.

Select an option

Save drsimonj/5b2cfc428fce350676db5dc77c059052 to your computer and use it in GitHub Desktop.

Revisions

  1. drsimonj revised this gist Jun 6, 2017. 1 changed file with 11 additions and 1 deletion.
    12 changes: 11 additions & 1 deletion model and predict problems
    Original file line number Diff line number Diff line change
    @@ -33,4 +33,14 @@ gamlss:::predict.gamlss(fit, newdata = d[1:5,])
    d <- d[1:10,]
    gamlss:::predict.gamlss(fit, newdata = d[1:5,])
    rm(d)
    gamlss:::predict.gamlss(fit, newdata = d[1:5,])
    gamlss:::predict.gamlss(fit, newdata = d[1:5,])

    # predict for Generalized Linear Models omits missing values unless data is explicitly added
    d <- datasets::iris
    d[1,1] <- NA
    a <- predict(stats::glm(Species=="setosa" ~ ., data = d))
    b <- predict(stats::glm(Species=="setosa" ~ ., data = d), newdata = d)
    length(a)
    length(b)
    sum(is.na(a))
    sum(is.na(b))
  2. drsimonj revised this gist May 17, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion model and predict problems
    Original file line number Diff line number Diff line change
    @@ -32,5 +32,5 @@ fit <- gamlss::gamlss(vs ~ hp + wt, data = d, family = gamlss.dist::BI())
    gamlss:::predict.gamlss(fit, newdata = d[1:5,])
    d <- d[1:10,]
    gamlss:::predict.gamlss(fit, newdata = d[1:5,])
    d <- NULL
    rm(d)
    gamlss:::predict.gamlss(fit, newdata = d[1:5,])
  3. drsimonj revised this gist May 17, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion model and predict problems
    Original file line number Diff line number Diff line change
    @@ -32,5 +32,5 @@ fit <- gamlss::gamlss(vs ~ hp + wt, data = d, family = gamlss.dist::BI())
    gamlss:::predict.gamlss(fit, newdata = d[1:5,])
    d <- d[1:10,]
    gamlss:::predict.gamlss(fit, newdata = d[1:5,])
    rm(d)
    d <- NULL
    gamlss:::predict.gamlss(fit, newdata = d[1:5,])
  4. drsimonj revised this gist May 17, 2017. No changes.
  5. drsimonj revised this gist May 17, 2017. 1 changed file with 11 additions and 1 deletion.
    12 changes: 11 additions & 1 deletion model and predict problems
    Original file line number Diff line number Diff line change
    @@ -23,4 +23,14 @@ predict(fit)$class
    d <- d[1:3, ]
    predict(fit)$class
    rm(d)
    predict(fit)$class
    predict(fit)$class

    # Generalized Additive Models for Location Scale and Shape (gamlss from gamlss package)
    # searches for original data in global environment when predicting new data
    d <- datasets::mtcars[1:20,]
    fit <- gamlss::gamlss(vs ~ hp + wt, data = d, family = gamlss.dist::BI())
    gamlss:::predict.gamlss(fit, newdata = d[1:5,])
    d <- d[1:10,]
    gamlss:::predict.gamlss(fit, newdata = d[1:5,])
    rm(d)
    gamlss:::predict.gamlss(fit, newdata = d[1:5,])
  6. drsimonj revised this gist May 3, 2017. 1 changed file with 10 additions and 1 deletion.
    11 changes: 10 additions & 1 deletion model and predict problems
    Original file line number Diff line number Diff line change
    @@ -14,4 +14,13 @@ d <- datasets::airquality
    fit <- lme4::lmer(Ozone ~ Wind + (Wind | Month), d)
    nrow(d)
    length(lme4:::predict.merMod(fit))
    length(lme4:::predict.merMod(fit, newdata = d))
    length(lme4:::predict.merMod(fit, newdata = d))

    ## predict for Linear Discriminant Analysis (lda from MASS package) searches for object in global environment
    d <- iris[c(1:5, 51:55, 101:105),]
    fit <- MASS::lda(Species ~ ., d)
    predict(fit)$class
    d <- d[1:3, ]
    predict(fit)$class
    rm(d)
    predict(fit)$class
  7. drsimonj revised this gist May 3, 2017. 1 changed file with 8 additions and 1 deletion.
    9 changes: 8 additions & 1 deletion model and predict problems
    Original file line number Diff line number Diff line change
    @@ -7,4 +7,11 @@ predict(d)

    ## predict for Principal Components (prcomp) can't recreate new variables defined in formula
    fit <- prcomp(~.*., mtcars[1:25, ])
    predict(fit, mtcars[26:32,])
    predict(fit, mtcars[26:32,])

    ## predict for Linear Mixed Effects Model (lmer from lme4 package) doesn't match when data omitted or included as `newdata`
    d <- datasets::airquality
    fit <- lme4::lmer(Ozone ~ Wind + (Wind | Month), d)
    nrow(d)
    length(lme4:::predict.merMod(fit))
    length(lme4:::predict.merMod(fit, newdata = d))
  8. drsimonj revised this gist May 3, 2017. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions model and predict problems
    Original file line number Diff line number Diff line change
    @@ -4,3 +4,7 @@ fit <- aov(hp ~ am * cyl, d)
    predict(fit)
    d <- NULL
    predict(d)

    ## predict for Principal Components (prcomp) can't recreate new variables defined in formula
    fit <- prcomp(~.*., mtcars[1:25, ])
    predict(fit, mtcars[26:32,])
  9. drsimonj renamed this gist May 3, 2017. 1 changed file with 0 additions and 0 deletions.
  10. drsimonj created this gist May 3, 2017.
    6 changes: 6 additions & 0 deletions twidlr motivation: model and predict problems
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    ## predict for Analysic of Variance (aov) searches for object in global environment
    d <- datasets::mtcars
    fit <- aov(hp ~ am * cyl, d)
    predict(fit)
    d <- NULL
    predict(d)