File: fitted.R

package info (click to toggle)
r-cran-gss 2.1-3-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,740 kB
  • ctags: 1,400
  • sloc: fortran: 5,241; ansic: 1,388; makefile: 1
file content (52 lines) | stat: -rw-r--r-- 2,268 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
## Obtain fitted values from ssanova objects
fitted.ssanova <- function(object,...)
{
    mf <- object$mf
    if (!is.null(object$random)) mf$random <- I(object$random$z)
    predict(object,mf)
}

## Obtain residuals from ssanova objects
residuals.ssanova <- function(object,...)
{
    y <- model.response(object$mf,"numeric")
    as.numeric(y-fitted.ssanova(object))
}

## Obtain fitted values in working scale from gssanova objects
fitted.gssanova <- function(object,...)
{
    as.numeric(object$eta)
}

## Obtain residuals from gssanova objects
residuals.gssanova <- function(object,type="working",...)
{
    y <- model.response(object$mf,"numeric")
    wt <- model.weights(object$mf)
    offset <- NULL
    if ((object$family=="nbinomial")&(!is.null(object$nu))) y <- cbind(y,object$nu)
    dat <- switch(object$family,
                  binomial=mkdata.binomial(y,object$eta,wt,offset),
                  nbinomial=mkdata.nbinomial(y,object$eta,wt,offset,object$nu),
                  poisson=mkdata.poisson(y,object$eta,wt,offset),
                  inverse.gaussian=mkdata.inverse.gaussian(y,object$eta,wt,offset),
                  Gamma=mkdata.Gamma(y,object$eta,wt,offset),
                  weibull=mkdata.weibull(y,object$eta,wt,offset,list(object$nu,FALSE)),
                  lognorm=mkdata.lognorm(y,object$eta,wt,offset,list(object$nu,FALSE)),
                  loglogis=mkdata.loglogis(y,object$eta,wt,offset,list(object$nu,FALSE)))
    res <- as.numeric(dat$ywk - object$eta)
    if (!is.na(charmatch(type,"deviance"))) {
        dev.resid <- switch(object$family,
                            binomial=dev.resid.binomial(y,object$eta,wt),
                            nbinomial=dev.resid.nbinomial(y,object$eta,wt),
                            poisson=dev.resid.poisson(y,object$eta,wt),
                            inverse.gaussian=dev.resid.inverse.gaussian(y,object$eta,wt),
                            Gamma=dev.resid.Gamma(y,object$eta,wt),
                            weibull=dev.resid.weibull(y,object$eta,wt,object$nu),
                            lognorm=dev.resid.lognorm(y,object$eta,wt,object$nu),
                            loglogis=dev.resid.loglogis(y,object$eta,wt,object$nu))
        res <- sqrt(dev.resid)*sign(res)
    }
    res
}