Reputation: 141
A quick question regarding the logistic regression in R. Let's assume that I fitted the logistic regression for the BreastCancer dataset with Cell.size and Cell.shape as predictors to predict whether patient is Benign or Malignant.
library(mlbench)
data(BreastCancer)
data1<- BreastCancer
levels(data1$Class)<- c(0,1) # binary outcome
data1<- data.frame(sapply(data1, as.numeric)) #converting from factors to num
data1$Class<- data1$Class-1
mylogit1<- glm(Class~Cell.size+Cell.shape, data=data1, family="binomial")
This would give me exact model: Y= -5.4771+0.7672*Cell.size+0.8223*Cell.shape to predict patients' class (I would use 1/(1+exp(-Y) as the corresponding risk).
Now I want to fix this model and try to add new variable, Cl.thickness for example. My aim is to fit the logistic regression with the base in the form of
Y= -5.4771+ 0.7672*Cell.size+0.8223*Cell.shape+a+b*Cl.thickness
where a, b are the parameters which I want to estimate.
How can I do this in R? It's not that I want to fix the Intercept but I want to fix some part of the model. Thanks!
Upvotes: 2
Views: 772
Reputation: 270248
Normally one would update the formula and run the model again like this:
update(mylogit1, . ~ . + Cl.thickness)
but if you really want to fix the coefficients then
update(mylogit1, . ~ Cl.thickness + offset(predict(mylogit1)))
Upvotes: 3