I have rows of data with columns age, sex, education and income.

I am doing homework that asks me to predict income with naive Bayes in R with the formula
income ~ age + sex + educ

I know formulas tell R the shape of the model to apply in the method.

I also know that formulas don't refer to any specific variables in a dataset -- they only give the shape of the data.

So with all that said, what does the formula income ~ age + sex + educ mean? I am guessing that it means

p(income|age, sex, income) = P(y|x1,x2,x3) = P(x1|y) * P(x2|y) * P(x3|y) * P(y)

Unless you're using terms differently that what I understand you to mean, you're mistaken when you assert that "formulas don't refer to any specific variables in a dataset". They certainly do refer to specific variables, explicitly by name.

See this stackoverflow answer for some background information and where R formulas originate.

Formulas are used for many purposes in R, and a specific component of a formula (such as a variable name or an operator) may have a somewhat different meaning in a different context.

The meaning of the formula in plot(y ~ x1 + x2, data=mydata) and in lm(y ~ x1 + x2, data=mydata) and in glm(y ~ x1 + x2, family=binomial, data=mydata) are all somewhat different ... and as you go further afield, meanings can change even more, even between packages doing very similar things.

So what that formula might mean in R is very context dependent -- and we don't have sufficient context.

(You don't even mention whether you're using a package in R or building something yourself.)

Given this is a naive Bayes classifier, your interpretation certainly makes sense (think in terms of logs, for example), and likely that's what I'd have anticipated it to mean, but that's not really anything to do with R unless you're using some particular package... whose specific interpretation of formulas we might then be able to explain.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.