Naive Bayes using e1071::naiveBayes

nb(dataset, rvar, evar, laplace = 0, data_filter = "", envir = parent.frame())

Arguments

dataset

Dataset

rvar

The response variable in the logit (probit) model

evar

Explanatory variables in the model

laplace

Positive double controlling Laplace smoothing. The default (0) disables Laplace smoothing.

data_filter

Expression entered in, e.g., Data > View to filter the dataset in Radiant. The expression should be a string (e.g., "price > 10000")

envir

Environment to extract data from

Value

A list with all variables defined in nb as an object of class nb

Details

See https://radiant-rstats.github.io/docs/model/nb.html for an example in Radiant

See also

summary.nb to summarize results

plot.nb to plot results

predict.nb for prediction

Examples

nb(titanic, "survived", c("pclass", "sex", "age")) %>% summary()
#> Naive Bayes Classifier #> Data : titanic #> Response variable : survived #> Levels : Yes, No in survived #> Explanatory variables: pclass, sex, age #> Laplace : 0 #> Nr obs : 1,043 #> #> A-priori probabilities: #> survived #> Yes No #> 0.407 0.593 #> #> Conditional probabilities (categorical) or means & st.dev (numeric): #> pclass #> survived 1st 2nd 3rd #> Yes 0.421 0.271 0.308 #> No 0.167 0.236 0.597 #> #> sex #> survived female male #> Yes 0.682 0.318 #> No 0.155 0.845 #> #> age #> survived mean st.dev #> Yes 28.819 15.004 #> No 30.497 13.881 #>
nb(titanic, "survived", c("pclass", "sex", "age")) %>% str()
#> List of 10 #> $ model :List of 7 #> ..$ apriori : 'table' int [1:2(1d)] 425 618 #> .. ..- attr(*, "dimnames")=List of 1 #> .. .. ..$ dataset[[1]]: chr [1:2] "Yes" "No" #> ..$ tables :List of 3 #> .. ..$ pclass: 'table' num [1:2, 1:3] 0.421 0.167 0.271 0.236 0.308 ... #> .. .. ..- attr(*, "dimnames")=List of 2 #> .. .. .. ..$ dataset[[1]]: chr [1:2] "Yes" "No" #> .. .. .. ..$ pclass : chr [1:3] "1st" "2nd" "3rd" #> .. ..$ sex : 'table' num [1:2, 1:2] 0.682 0.155 0.318 0.845 #> .. .. ..- attr(*, "dimnames")=List of 2 #> .. .. .. ..$ dataset[[1]]: chr [1:2] "Yes" "No" #> .. .. .. ..$ sex : chr [1:2] "female" "male" #> .. ..$ age : num [1:2, 1:2] 28.8 30.5 15 13.9 #> .. .. ..- attr(*, "dimnames")=List of 2 #> .. .. .. ..$ dataset[[1]]: chr [1:2] "Yes" "No" #> .. .. .. ..$ age : NULL #> ..$ levels : chr [1:2] "Yes" "No" #> ..$ isnumeric: Named logi [1:3] FALSE FALSE TRUE #> .. ..- attr(*, "names")= chr [1:3] "pclass" "sex" "age" #> ..$ call : language naiveBayes.default(x = dataset[, -1, drop = FALSE], y = dataset[[1]], laplace = laplace) #> ..$ residuals: logi NA #> ..$ model : tibble [1,043 × 4] (S3: tbl_df/tbl/data.frame) #> .. ..$ survived: Factor w/ 2 levels "Yes","No": 1 1 2 2 2 1 1 2 1 2 ... #> .. ..$ pclass : Factor w/ 3 levels "1st","2nd","3rd": 1 1 1 1 1 1 1 1 1 1 ... #> .. ..$ sex : Factor w/ 2 levels "female","male": 1 2 1 2 1 2 1 2 1 2 ... #> .. ..$ age : num [1:1043] 29 0.917 2 30 25 ... #> .. ..- attr(*, "description")= chr "## Titanic\n\nThis dataset describes the survival status of individual passengers on the Titanic. The titanic d"| __truncated__ #> ..- attr(*, "class")= chr "naiveBayes" #> $ form :Class 'formula' language survived ~ pclass + sex + age #> .. ..- attr(*, ".Environment")=<environment: 0xc759ad0> #> $ lev : chr [1:2] "Yes" "No" #> $ vars : chr [1:3] "pclass" "sex" "age" #> $ not_vary : chr(0) #> $ df_name : chr "titanic" #> $ rvar : chr "survived" #> $ evar : chr [1:3] "pclass" "sex" "age" #> $ laplace : num 0 #> $ data_filter: chr "" #> - attr(*, "class")= chr [1:3] "nb" "model" "list"