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

Fixes issue#48 added check for possible use of poly() #49

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions R/calibrate.R
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,8 @@ calibrate.lm <- function(object, y0, interval = c("inversion", "Wald", "none"),
adjust = c("none", "Bonferroni", "Scheffe"), k, ...) {

# Check model formula for correctness
xname <- all.vars(stats::formula(object)[[3L]])
yname <- all.vars(stats::formula(object)[[2L]])
xname <- all.vars(object$terms[[3L]])
yname <- all.vars(object$terms[[2L]])
if (length(xname) != 1L) {
stop("Only one independent variable allowed.")
}
Expand All @@ -288,19 +288,19 @@ calibrate.lm <- function(object, y0, interval = c("inversion", "Wald", "none"),
# Check for intercept using terms object from model fit. Alternatively, this
# can also be checked by testing if the first column name in model.matrix is
# equal to "(Intercept)".
if (!attr(stats::terms(object), "intercept")) {
if (!attr(object$terms, "intercept")) {
stop(paste(deparse(substitute(object)), "must contain an intercept."))
}

# Extract x values and y values from model frame
mf <- stats::model.frame(object)
if (ncol(mf) != 2) {
mf <- object$model
if (ncol(mf) != 2 || !is.vector(mf[,2]) ) {
stop("calibrate only works for the simple linear regression model.")
}
x <- stats::model.matrix(object)[, 2]
y <- stats::model.response(mf)
x <- mf[,2]
y <- mf[,1]

# Eta - mean response or mean of observed respone values
# Eta - mean response or mean of observed response values
eta <- mean(y0) # mean of new observations
m <- length(y0) # number of new observations
if (mean.response && m > 1) stop("Only one mean response value allowed.")
Expand Down
Binary file modified tests/testthat/Rplots.pdf
Binary file not shown.
5 changes: 3 additions & 2 deletions tests/testthat/test-calibrate.R
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,13 @@ test_that("errors get handled apprropriately", {
# Multiple linear regression
mlr.fit1 <- lm(weight ~ time + I(time ^ 2), data = crystal)
mlr.fit2 <- lm(cbind(weight, weight ^ 2) ~ time, data = crystal)
mlr.poly <- lm(weight ~ poly(time,2), data = crystal)

# Expectations
expect_error(calibrate(nls.fit, y0 = c(309, 296, 419)))
expect_error(calibrate(mlr.fit1, y0 = c(309, 296, 419)))
expect_error(calibrate(mlr.fit1, y0 = c(309, 296, 419)))

expect_error(calibrate(mlr.fit2, y0 = c(309, 296, 419)))
expect_error(calibrate(mlr.poly, y0 = c(309, 296, 419)))
})


Expand Down