CS计算机代考程序代写 Pkg.add(“StatsBase”)

Pkg.add(“StatsBase”)
Pkg.add(“HypothesisTests”)

using HypothesisTests
import HypothesisTests.confint

###########################################
# General Statistical functions on Collection
# – count, sum, mean

count(agr::Aggregation) = agr.n
count(sv::StoredValues) = sv.loc – 1

sum(agr::Aggregation) = agr.sum
sum(sv::StoredValues) = sum( values(sv))

mean(agr::Aggregation) = sum(agr) / count(agr)
mean(sv::StoredValues) = mean( values(sv))

###########################################
# More simple statistical measures
# – does not apply to Sum collections
# – var, minimum, maximum. extrema

# helper function for the SimpleStats implementation of var
sumsq(stats::NormalStats) = stats.sumSq
biasedvar(stats::NormalStats) = sumsq(stats)/count(stats) – mean(stats)^2

var(stats::NormalStats) = biasedvar(stats) * stats.n / (stats.n – 1)
var(sv::StoredValues) = var( values(sv))

function var(stats::BinomialStats)
p = mean(stats)
p * (1 – p) / count(stats)
end

std(stats::SimpleStats) = sqrt( var(stats))
std(sv::StoredValues) = std( values(sv))

function confint(stats::BinomialStats; level = 0.95, tail = :both, method = :wilson)
confint(BinomialTest(sum(stats), count(stats)); level, tail, method)
end

function confint(stats::NormalStats; level = 0.95, tail = :both)
confint( OneSampleTTest(mean(stats), std(stats), count(stats)); level, tail)
end

function confint(stats::StoredValues; level = 0.95, tail = :both)
confint(OneSampleTTest(values(stats); level, tail); level, tail)
end

minimum(stats::NormalStats) = stats.min
minimum(sv::StoredValues) = minimum( values(sv))

maximum(stats::NormalStats) = stats.max
maximum(sv::StoredValues) = maximum( values(sv))

extrema(stats::NormalStats) = (stats.min, stats.max)
extrema(sv::StoredValues) = extrema( values(sv))

###########################################
# Non-Parametric statistical measures
# – only applis to StoredValues collections
# – median, quantile

median(sv::StoredValues) = median( values(sv))
quantile(sv::StoredValues, p) = quantile( values(sv), p)