({{, (RefLink[NominalVariables, paclet:ref/NominalVariables]) 
is an option for statistical functions such as (RefLink[LinearModelFit, paclet:ref/LinearModelFit]) that specifies which variables should be treated as having discrete values specified by names.}})

OpenersNotesSection(Spacer1)Details

Possible settings for (RefLink[NominalVariables, paclet:ref/NominalVariables]) include:

When (RefLink[NominalVariables, paclet:ref/NominalVariables])->(RefLink[Automatic, paclet:ref/Automatic]), different methods are used to detect nominal variables. In functions returning (RefLink[FittedModel, paclet:ref/FittedModel])[…], variables with non-numeric data values are treated as nominal.

In linear models, a nominal variable v with possible values (Subscript[s, 1]), (Subscript[s, 2]), … is represented as a collection of variables with values 1 or 0 corresponding to each case v==(Subscript[s, i]).

OpenersPrimaryExamplesSection(Spacer1)Examples  (6)

OpenersExampleSection0(Spacer1)Basic Examples  (1)

Define some data:

data={{a,0,1},{b,2,2},{a,2,1.8},{b,0,2.5}};

Fit the data, treating the first variable as a nominal variable:

nom=LinearModelFit[data,{x,y},{x,y},NominalVariables->x]

See the functional form:

Normal[nom]

Treat all variables as nominal:

LinearModelFit[data,{x,y},{x,y},NominalVariables->All]//Normal

OpenersExampleSection1(Spacer1)Scope  (2)

Automatically select nominal variables:

LinearModelFit[{{a,1},{b,2},{a,1.8},{b,2.5},{c,4},{c,5.2}},x,x,NominalVariables->Automatic]

Normal[%]

Specify nominal variables in (RefLink[GeneralizedLinearModelFit, paclet:ref/GeneralizedLinearModelFit]):

GeneralizedLinearModelFit[{{a,1},{b,2},{a,1.8},{b,2.5},{c,4},{c,5.2}},x,x,ExponentialFamily->"Gamma",NominalVariables->x]

With (RefLink[LogitModelFit, paclet:ref/LogitModelFit]):

LogitModelFit[{{a,1,.2},{b,2,.3},{a,1.8,.5},{b,2.5,.7},{c,4,.6},{c,5.2,.25}},{x,y},{x,y},NominalVariables->x]//Normal

With (RefLink[ProbitModelFit, paclet:ref/ProbitModelFit]):

ProbitModelFit[{{a,1,.2},{b,2,.3},{a,1.8,.5},{b,2.5,.7},{c,4,.6},{c,5.2,.25}},{x,y},{x,y},NominalVariables->x]//Normal

OpenersExampleSection3(Spacer1)Applications  (3)

Fit a one-way ANOVA model:

data={{a,1.},{b,1.4},{c,3.9},{a,4.},{b,1.6},{c,2.8},{a,2.1},{b,1.1},{c,4.2}};

lm=LinearModelFit[data,x,x,NominalVariables->All]

Obtain the ANOVA table:

lm["ANOVATable"]

Compute the model estimates for the three groups:

Map[lm,{a,b,c}]

Fit a two-way ANOVA model with interaction term:

data={{a,1,0.8},{b,2,3.},{c,1,1.9},{a,2,4.6},{b,1,3.2`},{c,2,2.4},{a,1,4.1},{b,2,4.5},{c,1,4.8},{a,2,1.},{b,1,4.5},{c,2,1.8}};

lm=LinearModelFit[data,{x,y,x y},{x,y},NominalVariables->All]

Obtain the ANOVA table:

lm["ANOVATable"]

Compute estimates for each cell:

vals=Flatten[Table[{x,y,lm[x,y]},{x,{a,b,c}},{y,{1,2}}],1]

Results in a table:

Grid[Join[{{"x\\y",1,2}},Join[{{a},{b},{c}},Partition[vals[[All,-1]],2],2]],Dividers->{{False,True},{False,True}}]

Fit an ANCOVA model:

data=Map[#/{1,1/2,1}&,{{b,1,5.9},{b,2,4.2},{a,3/2,4.3},{b,4,5.2},{b,5,7.1},{b,6,9.5},{c,7,9.3},{c,8,11.2},{a,9,16.5},{a,10,13.7}}];

lm=LinearModelFit[data,{x,y},{x,y},NominalVariables->x]

Visualize curves for the three x categories and label using (RefLink[Tooltip, paclet:ref/Tooltip]):

Plot[{Tooltip[lm[a,y],"x==a"],Tooltip[lm[b,y],"x==b"],Tooltip[lm[c,y],"x==c"]},{y,0,10}]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[LinearModelFit, paclet:ref/LinearModelFit])  ▪  (RefLink[GeneralizedLinearModelFit, paclet:ref/GeneralizedLinearModelFit])  ▪  (RefLink[LogitModelFit, paclet:ref/LogitModelFit])  ▪  (RefLink[ProbitModelFit, paclet:ref/ProbitModelFit])  ▪  (RefLink[CoxModelFit, paclet:ref/CoxModelFit])  ▪  (RefLink[FittedModel, paclet:ref/FittedModel])  ▪  (RefLink[DiscreteIndicator, paclet:ref/DiscreteIndicator])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Statistical Model Analysis, paclet:guide/StatisticalModelAnalysis])}, {▪(RefLinkPlain[Survival Analysis, paclet:guide/SurvivalAnalysis])}})}})