0

This is the error message:

Error in qt((1 - level)/2, df) : Non-numeric argument to mathematical function

What I am trying to do is to fit a model to check the association between SBP and age with sex and race adjustments. My code uses the uwIntroStats package: the code to fit the model works. Sex (male) is coded as 0 for female and 1 for male, race is coded 1 to 4.

library(uwIntroStats)
data(mri)
model <- regress("mean", sbp~age*male+as.factor(race), data = mri)
predict(model, data.frame(age=70,male=0,race=2),interval="prediction")

Any reasons why the error occurs and how to fix it? Thanks!

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
  • 3
    Please share a portion of your data. Check out [this link](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) on how to make a reproducible example if you're unsure – astrofunkswag Feb 14 '19 at 00:00
  • @astrofunkswag, `library(uwIntroStats); data(mri)` will make this reproducible. – Ben Bolker Feb 14 '19 at 01:43

1 Answers1

0

You need to name the newdata argument: otherwise the predict method thinks you're trying to specify the next unmatched argument, which is level. From ?predict.uRegress:

## S3 method for class 'uRegress'
predict(object,interval="prediction",level=0.95, ...)

So

predict(model, newdata=data.frame(age=70,male=0,race=2),
        interval="prediction")

works (you don't actually need to specify interval="prediction" - that's the default value).

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453