我發現這樣做的方式涉及到使用offset()函數(詳見Pawitan,Y。(2001)'In All Likelihood'p172)。 由@BenBolker和@GavinSimpson給出的答案比這更好,因爲他們引用的軟件包將完成所有這些工作,還有更多。 我發佈這個是因爲它以另一種方式圍繞它,還有,「手動」繪製東西有時對於學習來說很好。它教會了我很多。
sexi <- as.numeric(data.frame$sex)-1 #recode a factor as 0/1 numeric
beta <- numeric(60) #Set up vector to Store the betas
deviance <- numeric(60) #Set up vector to Store the deviances
for (i in 1:60){
beta[i] <- 0.5 - (0.01*i)
#A vector of values either side of the fitted MLE (in this case -0.22)
mod <- update(model,
.~. - sex #Get rid of the fitted variable
+ offset( I(sexi*beta[i]) ) #Replace with offset term.
)
deviance[i] <- mod$deviance #Store i'th deviance
}
best <- which.min(deviance)
#Find the index of best deviance. Should be the fitted value from the model
deviance0 <- deviance - deviance[best]
#Scale deviance to zero by subtracting best deviance
betahat <- beta[best] #Store best beta. Should be the fitted value.
stderror <- 0.12187 #Store the std error of sex, found in summary(model)
quadratic <- ((beta-betahat)^2)*(1/(stderror^2))
#Quadratic reference function to check quadratic assumption against
x11()
plot(beta,deviance0,type="l",xlab="Beta(sex)",ylim=c(0,4))
lines(beta,quadratic,lty=2,col=3) #Add quadratic reference line
abline(3.84,0,lty=3) #Add line at Deviance = 3.84
謝謝加文。這看起來就像我正在尋找的那種東西。我沒有意識到人們會很快回復。我的回答只是一些代碼,現在看起來有些多餘: -/ – MatW 2012-03-20 14:10:55
不,請張貼它---因爲許多不同方式的事情可以幫助未來毫無戒心的用戶。 – 2012-03-20 14:12:49
我剛剛發現我無法發佈七個小時,因爲我的聲譽不夠高。我會在稍後發佈。謝謝你的幫助。 – MatW 2012-03-20 14:15:11