one_sample: Deal with one (normal) sample

View source: R/one_sample.R

one_sampleR Documentation

Deal with one (normal) sample

Description

Deal with one sample x, especially normal. Report descriptive statistics, plot, interval estimation and test of hypothesis of x.

Usage

one_sample(x, mu = Inf, sigma = -1, side = 0, alpha = 0.05)

Arguments

x

A numeric vector.

mu

mu plays two roles.

In two sided or one sided interval estimation (or test of hypothesis) of sigma^2 of one normal sample, mu is the population mean. When it is known, input it, and the function computes the interval endpoints (or chi-square statistic) using a chi-square distribution with degree of freedom n. When it is unknown, ignore it (the default), and the function computes the interval endpoints (or chi-square statistic) using a chi-square distribution with degree of freedom n-1.

In two sided or one sided test of hypothesis of mu of one normal sample, mu is mu0 in the null hypothesis, and mu0 = if (mu < Inf) mu else 0.

sigma

sigma plays two roles.

In two sided or one sided interval estimation (or test of hypothesis) of mu of one normal sample, sigma is the standard deviation of the population. sigma>=0 indicates it is known, and the function computes the interval endpoints (or Z statistic) using a standard normal distribution. sigma<0 indicates it is unknown, and the function computes the interval endpoints (or T statistic) using a t distribution with degree of freedom n-1. Default to unknown standard deviation.

In two sided or one sided test of hypothesis of sigma^2 of one normal sample, sigma is sigma0 in the null hypothesis. Default is 1, i.e., H0: sigma^2 = 1.

side

side plays two roles and is used in four places.

In two sided or one sided interval estimation of mu of one normal sample, side is a parameter used to control whether to compute two sided or one sided interval estimation. When computing the one sided upper limit, input side = -1; when computing the one sided lower limit, input side = 1; when computing the two sided limits, input side = 0 (default).

In two sided or one sided interval estimation of sigma^2 of one normal sample, side is a parameter used to control whether to compute two sided or one sided interval estimation. When computing the one sided upper limit, input side = -1; when computing the one sided lower limit, input side = 1; when computing the two sided limits, input side = 0 (default).

In two sided or one sided test of hypothesis of mu of one normal sample, side is a parameter used to control two sided or one sided test of hypothesis. When inputting side = 0 (default), the function computes two sided test of hypothesis, and H1: mu != mu0; when inputting side = -1 (or a number < 0), the function computes one sided test of hypothesis, and H1: mu < mu0; when inputting side = 1 (or a number > 0), the function computes one sided test of hypothesis, and H1: mu > mu0.

In two sided or one sided test of hypothesis of sigma^2 of one normal sample, side is a parameter used to control two sided or one sided test of hypothesis. When inputting side = 0 (default), the function computes two sided test of hypothesis, and H1: sigma^2 != sigma0^2; when inputting side = -1 (or a number < 0), the function computes one sided test of hypothesis, and H1: sigma^2 < sigma0^2; when inputting side = 1 (or a number > 0), the function computes one sided test of hypothesis, and H1: sigma^2 > sigma0^2.

alpha

The significance level, a real number in [0, 1]. Default to 0.05. 1-alpha is the degree of confidence.

Value

A list with the following components:

mu_interval

It contains the results of interval estimation of mu.

mu_hypothesis

It contains the results of test of hypothesis of mu.

sigma_interval

It contains the results of interval estimation of sigma.

sigma_hypothesis

It contains the results of test of hypothesis of sigma.

Author(s)

Ying-Ying Zhang (Robert) robertzhangyying@qq.com

References

Zhang, Y. Y., Wei, Y. (2013), One and two samples using only an R funtion, \Sexpr[results=rd]{tools:::Rd_expr_doi("10.2991/asshm-13.2013.29")}.

Examples

x=rnorm(10, mean = 1, sd = 0.2); x
one_sample(x, mu = 1, sigma = 0.2, side = 1)
one_sample(x, sigma = 0.2, side = 1)
one_sample(x, mu = 1, side = 1)
one_sample(x)

OneTwoSamples documentation built on March 31, 2023, 11:49 p.m.