glmscore {augSIMEX} R Documentation

Score Value in Generalized Linear Model

Description

This function can be used to calculate the value of score function. This function can serve as a tool to assist the users in debugging their self-defined score function.

Usage

glmscore(beta, Y, data, weight, offset, family)


Arguments

 beta a vector specifying the value of parameters. Y a vector specifying the response. data a matrix or data frame of covariates. If this is for score function debugging purpose, see detail for the rearrangement of the dataset. weight a vector of weight. offset a vector of offset. family a glm “family” object.

Details

In a general setting, Y can be treated as a response and data as covariates.

This function helps to debug the user specified score function. The data are needed to be specially arranged such that the score function output can be successfully passed into augSIMEX function in a correct order. The data should be a matrix or data frame of a combination with error-prone covariates (in the order of err.var as in augSIMEX), other covariates and binary variable that is prone to misclassification. The intercept, if considered, should be included the category of “other covariates”.

Value

A matrix of n times m, where n is the number of observations and m is the number of parameters. Each entry in the matrix represents the calculated score value for subject i on parameter j. The vector of row sum will be the score value vector.

Author(s)

Qihuang Zhang and Grace Y. Yi.

References

McCullagh P. Generalized linear models[J]. European Journal of Operational Research, 1984, 16(3): 285-292.

glm

Examples

### The user specified function to be checked. (logit link in binomial family)
scorefunction=function(beta,Y,data,weight,offset){
results<-lapply(1:dim(data)[2],
FUN=function(i){
S<-lapply(1:dim(data)[1],function(x){
eta<- matrix(beta,nrow=1)
return(weight[x]*Y[x]*data[x,i]-weight[x]*exp(eta)/(1+exp(eta))*data[x,i])})
return(S)}
)
return(matrix(unlist(results),ncol=dim(data)[2]))
}

data(ToyUni)

### Data need to rearranged. See detail.
nsize<-length(ToyUni$Main[,"Y"]) data.in.score<-data.frame(intercept=1,X=ToyUni$Main[,"Xstar"],
W=ToyUni$Main[,"W"],Z=ToyUni$Main[,"Zstar"])

## compare. The results should be identical.
glmscore(rep(0,4),ToyUni$Main[,"Y"],data.in.score,rep(1,nsize), rep(0,nsize),family=binomial(link=logit)) scorefunction(rep(0,4),ToyUni$Main[,"Y"],data.in.score,rep(1,nsize),rep(0,nsize))


[Package augSIMEX version 3.7.4 Index]