2016-01-11 1 views
0

Quand je courais multinom(), disons Y ~ X1 + X2 + X3, si pour une ligne particulière X1 est NA (ce qui manque), mais Y, X2 et X3 tous ont une valeur, serait jeté toute cette ligne sur (comme il le fait dans SAS)? Comment les valeurs manquantes sont-elles traitées dans multinom()?Comment multinom() traite-t-il les valeurs NA par défaut?

Répondre

0

Vous pouvez spécifier le comportement

- na.omit and na.exclude: returns the object with observations removed if they contain any missing values; differences between omitting and excluding NAs can be seen in some prediction and residual functions 
- na.pass: returns the object unchanged 
- na.fail: returns the object only if it contains no missing values 

http://www.ats.ucla.edu/stat/r/faq/missing.htm

1

Voici un exemple simple (à partir ?multinom du paquet nnet) pour explorer les différentes na.action:

> library(nnet) 
> library(MASS) 
> example(birthwt) 
> (bwt.mu <- multinom(low ~ ., bwt)) 

créer Intentionnellement une NA valeur:

> bwt[1,"age"]<-NA # Intentionally create NA value 
> nrow(bwt) 
[1] 189 

Test de 4 différents na.action:

> predict(multinom(low ~ ., bwt, na.action=na.exclude)) # Note length is 189 
# weights: 12 (11 variable) 
initial value 130.311670 
iter 10 value 97.622035 
final value 97.359978 
converged 
    [1] <NA> 0 0 0 0 0 0 0 0 0 0 0 1 1 0 
[16] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
.... 

> predict(multinom(low ~ ., bwt, na.action=na.omit)) # Note length is 188 
# weights: 12 (11 variable) 
initial value 130.311670 
iter 10 value 97.622035 
final value 97.359978 
converged 
    [1] 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 
[38] 0 0 0 0 0 0 1 1 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 1 1 0 0 0 0 
..... 

> predict(multinom(low ~ ., bwt, na.action=na.fail)) # Generates error 
Error in na.fail.default(list(low = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, : 
    missing values in object 

> predict(multinom(low ~ ., bwt, na.action=na.pass)) # Generates error 
Error in qr.default(X) : NA/NaN/Inf in foreign function call (arg 1) 

Alors na.exclude génère un NA dans la prédiction en na.omit omettait entièrement. na.pass et na.fail ne créeront pas le modèle. Si aucune valeur n'est définie pour na.action, la valeur par défaut est la suivante:

> getOption("na.action") 
[1] "na.omit"