Statistics 计算方差

Statistics 计算方差,statistics,Statistics,我有自由度和中庸。我需要计算标准偏差 非常感谢您的帮助。 谢谢你仍然不能100%确定你想要做什么,但是这里有一个尝试(使用95%的t统计范围)。。。我只有一个文件(这是您粘贴的3个元素),名为stats1。我正在使用awk从文件中提取相关字段,并将其扔到R awk -F'>' '$1 ~/Overall/{print $2}' stats* | Rscript -e 'qt( 0.975, as.numeric (readLines ("stdin"))) ' [1] 2.940089

我有自由度和中庸。我需要计算标准偏差

非常感谢您的帮助。
谢谢你

仍然不能100%确定你想要做什么,但是这里有一个尝试(使用95%的t统计范围)。。。我只有一个文件(这是您粘贴的3个元素),名为stats1。我正在使用awk从文件中提取相关字段,并将其扔到R

awk -F'>' '$1 ~/Overall/{print $2}' stats* | Rscript -e 'qt( 0.975, as.numeric (readLines ("stdin"))) '
[1]  2.940089  2.776445 12.706205

将一些文本处理或数据争论工具与统计软件包(如R)结合使用当然是有意义的(特别是,您可能希望使用R的
t.test(VECTOR,MU)
),但
awk
当然可以胜任这项任务,甚至可能具有某些优势。无论如何,我已经附加了一个(bash)脚本,它希望它的输入每行有一个数据观察,并按照脚本的“帮助”文档中的描述发出一行

下面是使用
t.test()
从输出中提取的内容,以及使用脚本运行的内容(t-test),以供比较:

#/bin/bash
#使用风险自负
#需要帮助:$0--帮助
版本=0.1.1
#要求:awk
BN=$(基本名称“$0”)
功能帮助{

cat的第一个建议是澄清您的问题,定义您的数据来自何处以及它的外观。此外,我不确定awk是否适合用于统计,尽管我非常喜欢它用于文本处理。您是否考虑过R?或任何不专门用于文本的编程语言:Ruby、Perl、Python都是标准的最近在大多数Linux发行版上。此外,我对统计数据不是很了解,但如果你有它所需要的所有输入,t统计可能不是一个“复杂的数学任务”。你的t统计数据的置信区间是多少?并不是说我是统计学家=}为什么脚本需要两个数据文件?datafile1和DataFile2的区别是什么?
$ R
> t.test(c(1,2,3), mu=0)
    One Sample t-test
t = 3.4641, df = 2, p-value = 0.07418
alternative hypothesis: true mean is not equal to 0
95 percent confidence interval:
 -0.4841377  4.4841377

$ (echo 1; echo 2; echo 3) | t-stat
3 2 0.666667 3.4641
#!/bin/bash
# USE AT YOUR OWN RISK
# For help: $0 --help
VERSION=0.1.1

# Requires: awk

BN=$(basename "$0")

function help {
cat <<EOF
Syntax: $0 [n1 [FILE]]

Compute the sample mean, the sample variance, and the t-statistic for
the array of numbers in column n1 of the input, where n1 defaults to 1,
and FILE defaults to STDIN.

The output consists of a single line of four values:

n mean variance t

where "n" is the sample size (possibly 0),
      "mean" is the sample mean,
      "variance" is the average of the squared deviations from the mean, and
      "t" is the sample t-statistic, computed as 
           mean * sqrt( n * ss / (n-1));

If a statistic cannot be computed, an asterisk (*) is used in its place.

If the value in the specified field in the input is null or
non-numeric, it is ignored.

If a file is specified as "-" then STDIN is read.

Example:

$BN <<< $'1\n2\n3'
3 2 2 3.4641

EOF
}

function die     { echo "$BN: $@" >&2 ; exit 1 ; }

case "$1" in
    -h | --help )
    help
    exit
    ;;
    -v | --verbose )
    VERBOSE=1
    shift
    ;;
esac

# Default:

file=-

if [ $# = 0 ] ; then
    f1=1
elif [ "$1" = - ] ; then
    f1=1
else
   f1="$1"
   shift
   check=`expr "$f1" : "\([0-9]*\)"`
   if [ "$f1" != "$check" ] ; then die a non-numeric field was specified ; fi
fi

if [ $# != 0 ] ; then file="$1" ; fi

awk -v verbose="$VERBOSE" -v f1="$f1" '
  BEGIN { a1=0; s1=0; n=0; }
  NF < f1 { next }
  $f1 == "" || ($f1+0 != $f1) { next }
  { n++; a1 += $f1; s1 += $f1*$f1; }

  END {
    s="*";
    if ( n == 0 ) {print 0, s, s, s; exit }
    avg = a1/n;
    var = s1/n - avg*avg;
    if (var == 0) { print n, avg, var, s; exit}
    tstat = avg * sqrt( (n-1) / var);
    print n, avg, var, tstat; 
  } ' "$file"