\name{Model}
\alias{Model}
\alias{model}
\alias{model_brief}


\title{Regression, Logit Regression, ANOVA, or t-test from a Model
 Specification}

\description{
Abbreviation: \code{model}, \code{model_brief}

Specify a model with a standard R \code{\link{formula}}, and \code{Model}
selects and runs the appropriate statistical procedure: OLS regression,
logit regression, ANOVA, or a t-test. The selection follows from the
analytic structure of the model's variables -- whether the response and
predictor variables are numerical or categorical, and how many unique
values they have. The analysis itself, with its full text and graphics
output, is produced by the corresponding \code{lessR} function:
\code{\link{Regression}}, \code{\link{Logit}}, \code{\link{ANOVA}}, or
\code{\link{ttest}}. Any parameter of the selected function can be passed
through the \code{Model} call.

By default the data exist in the data frame \code{d}, such as data read by
the \code{lessR} \code{\link{Read}} function.
}

\usage{
Model(my_formula, data=d, brief=getOption("brief"), xlab=NULL, \dots)

model_brief(\dots, brief=TRUE)

model(\dots)
}


\arguments{
  \item{my_formula}{Standard R \code{\link{formula}} for specifying a model.
       For example, for a response variable named Y and two predictor
       variables, X1 and X2, specify the corresponding linear model as
       Y ~ X1 + X2.}
  \item{data}{The default name of the data frame that contains the data for
       analysis is \code{d}, otherwise explicitly specify.}
  \item{brief}{If set to \code{TRUE}, reduced text output. Can change
       system default with the \code{\link{style}} function.}
  \item{xlab}{x-axis label for the graphics output of the logit and t-test
       analyses, defaults to the variable name, or, if present, the
       variable label.}
  \item{\dots}{Parameter values passed to the selected analysis function,
       \code{\link{Regression}}, \code{\link{Logit}}, \code{\link{ANOVA}},
       or \code{\link{ttest}}.}
}



\details{
OVERVIEW\cr
The purpose of \code{Model} is to select the appropriate statistical
procedure from the specified model and properties of the data. The analyst
specifies the model, the analytic question of interest; \code{Model}
identifies and runs the procedure that answers it. A message that precedes
the output of each analysis reports which procedure was selected and why.

SELECTION OF THE PROCEDURE\cr
Classify the response variable (before the tilde in the formula) and the
predictor variables (after the tilde) as categorical -- an R factor,
character, or logical variable -- or as numerical. The analysis follows
from that classification.

For a categorical response variable with exactly two categories, run a
logit regression with \code{\link{Logit}}, regardless of the type of the
predictor variables. A categorical response variable with more than two
categories is not supported.

For a numerical response variable:
\itemize{
\item If the values of the response variable are only 0 and 1, run a logit
 regression with \code{\link{Logit}}.
\item If there is a single categorical predictor variable with exactly two
 unique values, compare the two corresponding group means with
 \code{\link{ttest}}.
\item If all predictor variables are categorical, compare the group means
 with \code{\link{ANOVA}}.
\item Otherwise, that is, for predictor variables that are all numerical,
 or a mix of numerical and categorical variables, run an OLS regression
 with \code{\link{Regression}}, which for one numerical and one categorical
 predictor variable provides an analysis of covariance.
}

A numerical response variable with exactly two unique values other than 0
and 1 is intended as binary, so first transform its values to 0 and 1 with
\code{\link{recode}} before running \code{Model}.

For further details of each analysis, and the additional parameters
available for each, see the corresponding function:
\code{\link{Regression}}, \code{\link{Logit}}, \code{\link{ANOVA}}, and
\code{\link{ttest}}.
}

\value{
The value returned by the selected analysis function, invisibly.
The primary output is the text and graphics of the selected analysis.
}

\author{David W. Gerbing (Portland State University; \email{gerbing@pdx.edu})}

\seealso{
\code{\link{Regression}}, \code{\link{Logit}}, \code{\link{ANOVA}},
\code{\link{ttest}}, \code{\link{formula}}, \code{\link{lm}},
\code{\link{glm}}
}

\examples{
# Generate random data, place in data frame d
n <- 200
X1 <- rnorm(n)
X2 <- rnorm(n)
Y <- .7*X1 + .2*X2 + .6*rnorm(n)
Ybin <- cut(Y, breaks=2, labels=FALSE)
#  instead, if read data with the Read function
#   then the result is the data frame called d
d <- round(data.frame(X1, X2, Y, Ybin),2)
rm(Y); rm(Ybin); rm(X1); rm(X2)

# One-predictor regression
# Provide all default analyses including scatterplot etc.
Model(Y ~ X1)
# alternate form
model(Y ~ X1)

# Multiple regression model
# Provide all default analyses
Model(Y ~ X1 + X2)

# Logit analysis from a numeric response variable of 0's and 1's
d <- recode(Ybin, old=c(1,2), new=c(0,1), quiet=TRUE)
Model(Ybin ~ X1)

# t-test
Model(breaks ~ wool, data=warpbreaks)

# ANOVA analysis
# from a data frame other than the default d
# breaks is numerical, wool and tension are categorical
Model(breaks ~ wool + tension, data=warpbreaks)

# Analysis of covariance: one numerical and one categorical predictor
d <- Read("Employee", quiet=TRUE)
Model(Salary ~ Years + Gender)

# Logit analysis from a two-category response variable
Model(Gender ~ Salary)
}

% Add one or more standard keywords, see file 'KEYWORDS' in the
% R documentation directory.
\keyword{ regression }
