File: AIC-mclogit.R

package info (click to toggle)
r-cran-mclogit 0.9.6-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 328 kB
  • sloc: makefile: 2
file content (45 lines) | stat: -rw-r--r-- 1,177 bytes parent folder | download
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
# Contributed by Nic Elliot <nic_elliot@yahoo.co.uk>

AIC.mclogit <- function(object,...,k=2){
  
  devNdf <- function(object)
    unname(unlist(object[c("deviance","N","model.df")]))
  
  if (length(list(...))) {
    dvs <- sapply(list(object, ...), devNdf)
    nobs <- dvs[2,]
    if(length(unique(nobs))>1)
      warning("models are not all fitted to the same number of observations")
    val <- data.frame(df=dvs[3,],AIC=dvs[1,]+k*dvs[3,])
    Call <- match.call()
    Call$k <- NULL
    row.names(val) <- as.character(Call[-1L])
    val
  }
  else {
    dvs <- devNdf(object)
    dvs[1]+k*dvs[3]
  }
}

BIC.mclogit <- function(object,...){
  
  devNdf <- function(object)
    unname(unlist(object[c("deviance","N","model.df")]))
  
  if (length(list(...))) {
    dvs <- sapply(list(object, ...), devNdf)
    nobs <- dvs[2,]
    if(length(unique(nobs))>1)
      warning("models are not all fitted to the same number of observations")
    val <- data.frame(df=dvs[3,],BIC=dvs[1,]+log(dvs[2,])*dvs[3,])
    Call <- match.call()
    Call$k <- NULL
    row.names(val) <- as.character(Call[-1L])
    val
  }
  else {
    dvs <- devNdf(object)
    dvs[1]+log(dvs[2])*dvs[3]
  }
}