0
$\begingroup$

Question

Is R Forumula is to train a linear regression model?

If a response value "cancel probability" is a function of (age, height), then R Formula is to generate a model (w-age, w-height, w-bias)?

cancer_probability = w-age * age + w-loc * height + w-bias

And this is written as "RFormula":

cancer_probability ~ age + height

Is this RFormula about?

Background

Trying to understand what RFormula is. Went through multiple articles but they do not give a simple definition.

RFormula has fit and transform, hence it seems to me it is just a training algorithm, but could not find any article/book which simply says so. Hence not sure what it is for sure.

Suppose you’re interested in how the temperature varies with the month. Having lived through many Mays through Septembers in one place, you might guess is that the temperature generally increases in this data frame from month to month.

In this example, let’s say that Temperature depends on Month. Another way to say this is that Temperature is the dependent variable and Month is the independent variable.

An R formula incorporates these concepts and serves as the basis for many of R’s statistical functions and graphing functions.

Read the tilde operator (~) as “depends on.” Here’s how you can address the relationship between Temp and Month:

analysis <- lm(Temp ~ Month, data=airquality)

In R, formulas provide a general way of getting “special behaviour”. Rather than evaluating the values of the variables right away, they capture them so they can be interpreted by the function.

The majority of modelling functions in R use a standard conversion from formulas to functions. You’ve seen one simple conversion already: y ~ x is translated to y = a_1 + a_2 * x.

The generic function formula and its specific methods provide a way of extracting formulae which have been included in other objects.

RFormula selects columns specified by an R model formula. Currently we support a limited subset of the R operators, including ‘~’, ‘.’, ‘:’, ‘+’, and ‘-‘. The basic operators are:
~ separate target and terms
+ concat terms, “+ 0” means removing intercept
- remove a term, “- 1” means removing intercept
: interaction (multiplication for numeric values, or binarized categorical values)
. all columns except target
Suppose a and b are double columns, we use the following simple examples to illustrate the effect of RFormula:

y ~ a + b means model y ~ w0 + w1 * a + w2 * b where w0 is the intercept and w1, w2 are coefficients.
y ~ a + b + a:b - 1 means model y ~ w1 * a + w2 * b + w3 * a * b where w1, w2, w3 are coefficients.
$\endgroup$
0
$\begingroup$

R formulas are just a common grammar for practical model specifications.

When you input a dataset and a formula like : cancer_probability ~ age + height to a model fitting function. The function will know that it has to work on age and height predictors to provide a model to give a cancer probability output.

As mentionned in the Spark link you give at the bottom, this grammar rely on some convention, as introducing an intercept by default.

$\endgroup$

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.