The R Project SVN R

Rev

Rev 76150 | Rev 83699 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 76150 Rev 77246
Line 36... Line 36...
36
    two variances as being equal. If \code{TRUE} then the pooled
36
    two variances as being equal. If \code{TRUE} then the pooled
37
    variance is used to estimate the variance otherwise the Welch
37
    variance is used to estimate the variance otherwise the Welch
38
    (or Satterthwaite) approximation to the degrees of freedom is used.}
38
    (or Satterthwaite) approximation to the degrees of freedom is used.}
39
  \item{conf.level}{confidence level of the interval.}
39
  \item{conf.level}{confidence level of the interval.}
40
  \item{formula}{a formula of the form \code{lhs ~ rhs} where \code{lhs}
40
  \item{formula}{a formula of the form \code{lhs ~ rhs} where \code{lhs}
41
    is a numeric variable giving the data values and \code{rhs} a factor
41
    is a numeric variable giving the data values and \code{rhs} either 
-
 
42
    \code{1} for a one-sample or paired test or a factor
42
    with two levels giving the corresponding groups.}
43
    with two levels giving the corresponding groups. If \code{lhs} is of 
-
 
44
    class \code{"Pair"} and \code{rhs} is \code{1}, a paired test is done}
43
  \item{data}{an optional matrix or data frame (or similar: see
45
  \item{data}{an optional matrix or data frame (or similar: see
44
    \code{\link{model.frame}}) containing the variables in the
46
    \code{\link{model.frame}}) containing the variables in the
45
    formula \code{formula}.  By default the variables are taken from
47
    formula \code{formula}.  By default the variables are taken from
46
    \code{environment(formula)}.}
48
    \code{environment(formula)}.}
47
  \item{subset}{an optional vector specifying a subset of observations
49
  \item{subset}{an optional vector specifying a subset of observations
Line 99... Line 101...
99
 
101
 
100
## Classical example: Student's sleep data
102
## Classical example: Student's sleep data
101
plot(extra ~ group, data = sleep)
103
plot(extra ~ group, data = sleep)
102
## Traditional interface
104
## Traditional interface
103
with(sleep, t.test(extra[group == 1], extra[group == 2]))
105
with(sleep, t.test(extra[group == 1], extra[group == 2]))
-
 
106
 
104
## Formula interface
107
## Formula interface
105
t.test(extra ~ group, data = sleep)
108
t.test(extra ~ group, data = sleep)
-
 
109
 
-
 
110
## Formula interface to one-sample test
-
 
111
t.test(extra ~ 1, data = sleep)
-
 
112
 
-
 
113
## Formula interface to paired test
-
 
114
## The sleep data are actually paired, so could have been in wide format:
-
 
115
sleep2 <- reshape(sleep, direction = "wide", 
-
 
116
                  idvar = "ID", timevar = "group")
-
 
117
t.test(Pair(extra.1, extra.2) ~ 1, data = sleep2)
106
}
118
}
107
\keyword{htest}
119
\keyword{htest}