Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Binomial glm in `rsq` package: error: object not found

Tags:

r

It seems that whenever I use any of the rsq package functions (pcor for partial correlations; rsq and rsq.partial for R-squared) on a binomial glm which uses the two-column notation, I get an error - see below. The model actually is correct, fit goes perfectly, no data missing.

Is there something I can do about it?

Reproducible example:

require(rsq)
data(esoph)
model1 <- glm(cbind(ncases, ncontrols) ~ agegp + tobgp * alcgp,
              data = esoph, family = binomial)

pcor(model1)

Error in cbind(ncases, ncontrols) : object 'ncases' not found

rsq(model1)

Error in cbind(ncases, ncontrols) : object 'ncases' not found

rsq.partial(model1)

Error in cbind(ncases, ncontrols) : object 'ncases' not found

like image 822
Tomas Avatar asked Mar 16 '26 10:03

Tomas


1 Answers

You have to use attach(esoph) before applying the model. Like

data(esoph)


model1 <- glm(cbind(ncases, ncontrols) ~ agegp + tobgp * alcgp,
              data = esoph, family = binomial)

attach(esoph)
pcor(model1)
# $adjustment
#[1] FALSE
#$variable
#[1] "agegp"       "tobgp"       "alcgp"       "tobgp:alcgp"
#$partial.cor
#[1] 0.8092124 0.0000000 0.0000000 0.3815876

#Warning message:
#In (nLevels > 1) & (varcls == "factor") :
#longer object length is not a multiple of shorter object length

rsq(model1)
# [1] 0.826124

rsq.partial(model1)
#$adjustment
#[1] FALSE
#$variable
#[1] "agegp"       "tobgp"       "alcgp"       "tobgp:alcgp"
#$partial.rsq
#[1]  6.548247e-01 -6.661338e-16  0.000000e+00  1.456091e-01

detach(esoph)
like image 114
Bappa Das Avatar answered Mar 19 '26 02:03

Bappa Das



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!