mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 09:40:21 +00:00
Adding R example with .r extension
This commit is contained in:
29
samples/R/df.residual.r
Normal file
29
samples/R/df.residual.r
Normal file
@@ -0,0 +1,29 @@
|
||||
|
||||
df.residual.mira <- function(object, ...) {
|
||||
fit <- object$analyses[[1]]
|
||||
return(df.residual(fit))
|
||||
}
|
||||
|
||||
df.residual.lme <- function(object, ...) {
|
||||
return(object$fixDF[["X"]][1])
|
||||
}
|
||||
|
||||
df.residual.mer <- function(object, ...) {
|
||||
return(sum(object@dims[2:4] * c(1, -1, -1)) + 1)
|
||||
}
|
||||
|
||||
df.residual.default <- function(object, q = 1.3, ...) {
|
||||
df <- object$df.residual
|
||||
if (!is.null(df))
|
||||
return(df)
|
||||
|
||||
mk <- try(c <- coef(object), silent = TRUE)
|
||||
mn <- try(f <- fitted(object), silent = TRUE)
|
||||
if (inherits(mk, "try-error") | inherits(mn, "try-error"))
|
||||
return(NULL)
|
||||
n <- ifelse(is.data.frame(f) | is.matrix(f), nrow(f), length(f))
|
||||
k <- length(c)
|
||||
if (k == 0 | n == 0)
|
||||
return(NULL)
|
||||
return(max(1, n - q * k))
|
||||
}
|
||||
Reference in New Issue
Block a user