R/zzz.R

setClassUnion("param",c("numeric","NULL"))

setClass("scores", representation(phi = "function", Dphi = "function", param="param"))

### Define methods ###
setGeneric(name="getScores", def=function(object, x) {standardGeneric("getScores")})
setGeneric(name="getScoresDeriv", def=function(object, x) {standardGeneric("getScoresDeriv")})

setMethod("getScores", "scores",
        function(object, x) {

                if(is.null(object@param)) {
                        a<-object@phi(x)
                } else {
                        a<-object@phi(x, object@param)
                }

				ac<-a-mean(a)
				sigma<-sum(ac*ac)/(length(ac)+1)
                ac/sqrt(sigma)

        }
)

setMethod("getScoresDeriv", "scores",
        function(object, x) {
        if(is.null(object@param)) {
                aP<-object@Dphi(x)
				a<-object@phi(x)
        } else {
                aP<-object@Dphi(x, object@param)
				a<-object@phi(x,object@param)
        }

		ac<-a-mean(a)
		sigma<-sum(ac*ac)/(length(ac)+1)
        aP/sqrt(sigma)
		
}
)

Try the Rfit package in your browser

Any scripts or data that you put into this service are public.

Rfit documentation built on Sept. 8, 2023, 5:59 p.m.