2014-12-03 62 views
0

我最初想在我的前瞻Logistic回归模型(BinaryOutcomeVar〜ContinuousPredVar + ContinuousPredVar^2 + ContinuousPredVar^3)上运行boxTidwell()(在“车”包中找到)分析。我碰到的问题:boxTidwell函数可以处理二元结果变量吗?

Error in x - xbar : non-numeric argument to binary operator 
In addition: Warning message: 
In mean.default(x) : argument is not numeric or logical: returning NA 

所以,我创建了一个可再现例如用于证明错误:

不起作用:

boxTidwell(formula = Treatment ~ uptake, other.x = ~ poly(x = colnames(CO2)[c(1,2,4)], degree = 2), data = CO2) 

boxTidwell(y = CO2$Treatment, x = CO2$uptake)

作品:

boxTidwell(formula = prestige ~ income + education, other.x = ~ poly(x = women , degree = 2), data = Prestige) 

我一直在玩other.x参数,我猜是这个问题。

问题

因此,没有人知道,如果1. boxTidwell()函数与二元结果变量2. other.x背后的逻辑的作品,因为我不能让我的虚拟实例要么工作。

+0

所以你期望我们去寻找这个功能? – 2014-12-03 18:15:38

+0

恩,图书馆(汽车)?我应该把这个问题加入到这个问题吗 – 2014-12-03 18:16:26

+0

是的。每当你有一个非默认包的函数时,你应该包含一个加载包的库调用。 – 2014-12-03 18:17:36

回答

0

经过进一步搜索,它看起来像汽车::: boxTidwell不能处理公式中的二元结果变量,但它可以是手工编码:

require(MASS) 
require(car) 

d1<-read.csv("path for your csv file",sep=',',header=TRUE) 

x<-d1$explanatory variable name 
y<-d1$dependent variable name 

#FIT IS DONE USING THE glm FUNCTION 
m1res <- glm(y ~ x,family=binomial(link = "logit")) 
coeff1<- coefficients(summary(m1res)) 
lnx<-x*log(x) 
m2res <- glm(y ~ x+lnx ,family=binomial(link = "logit")) 
coeff2<- coefficients(summary(m2res)) 
alpha0<-1.0 
pvalue<-coeff2[3,4] 
pvalue 
beta1<-coeff1[2,1] 
beta2<-coeff2[3,1] 
iter<-0 
err<-1 
while (pvalue<0.1) { 
alpha <-(beta2/beta1)+alpha0 
err<-abs(alpha-alpha0) 
alpha0<-alpha 
mx<-x^alpha 
m1res <- glm(y ~ mx,family=binomial(link = "logit")) 
coeff1<- coefficients(summary(m1res)) 
mlnx<-mx*log(x) 
m2res <- glm(y ~ mx+mlnx ,family=binomial(link = "logit")) 
coeff2<- coefficients(summary(m2res)) 
pvalue<-coeff2[3,4] 
beta1<-coeff1[2,1] 
beta2<-coeff2[3,1] 
iter<- iter+1 
} 
# PRINT THE POWER TO CONSOLE 
alpha 

上面的代码摘自: https://sites.google.com/site/ayyalaprem/box-tidwelltransform