Skip to content

Commit 9b48acb

Browse files
committed
analytic se for scale parameter of a normal
1 parent 78d4d54 commit 9b48acb

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

R/ldGaussianunivariate.R

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,6 @@ exp[-(x-<span style='color:red'>&mu;</span>)&sup2; &frasl; 2<span style='color:b
188188
if(is.null(results)) return()
189189
if(is.null(table)) return()
190190

191-
if (options[["outputSE"]])
192-
table$addFootnote(gettextf("SE is not available."), colNames="se", rowNames="scale")
193-
194191
if (options[["biasCorrected"]])
195192
table$addFootnote(gettext("Unbiased with Bessel's correction."), colNames="estimate", rowNames="scale")
196193

@@ -216,9 +213,11 @@ exp[-(x-<span style='color:red'>&mu;</span>)&sup2; &frasl; 2<span style='color:b
216213

217214
if (options[["biasCorrected"]]){
218215
sigma2Ci <- sigma2 * df / rev(chiSq)
216+
seScale <- df
219217
} else {
220218
sigma2 <- sigma2 * df / n
221219
sigma2Ci <- sigma2 * n / rev(chiSq)
220+
seScale <- n
222221
}
223222

224223
mu <- mean(variable)
@@ -232,10 +231,30 @@ exp[-(x-<span style='color:red'>&mu;</span>)&sup2; &frasl; 2<span style='color:b
232231

233232
scale <- switch(
234233
options[["parametrization"]],
235-
sigma2 = data.frame(par="sigma2", parName="\u03C3\u00B2", estimate=sigma2, se=NA, lower=sigma2Ci[1], upper=sigma2Ci[2]),
236-
sigma = data.frame(par="sigma", parName="\u03C3", estimate=sqrt(sigma2), se=NA, lower=sqrt(sigma2Ci[1]), upper=sqrt(sigma2Ci[2])),
237-
tau = data.frame(par="tau", parName="\u03C4", estimate=1/sigma2, se=NA, lower=1/sigma2Ci[1], upper=1/sigma2Ci[2]),
238-
kappa = data.frame(par="kapp", parName="\u03BA", estimate=1/sqrt(sigma2), se=NA, lower=1/sqrt(sigma2Ci[1]), upper=1/sqrt(sigma2Ci[2]))
234+
sigma2 = data.frame(par="sigma2",
235+
parName="\u03C3\u00B2",
236+
estimate=sigma2,
237+
se=sigma2 * sqrt(2) / seScale,
238+
lower=sigma2Ci[1],
239+
upper=sigma2Ci[2]),
240+
sigma = data.frame(par="sigma",
241+
parName="\u03C3",
242+
estimate=sqrt(sigma2),
243+
se=sqrt(sigma2 / (2 * seScale)),
244+
lower=sqrt(sigma2Ci[1]),
245+
upper=sqrt(sigma2Ci[2])),
246+
tau = data.frame(par="tau",
247+
parName="\u03C4",
248+
estimate=1/sigma2,
249+
se=sqrt(2)/ (sigma2 * seScale),
250+
lower=1/sigma2Ci[2],
251+
upper=1/sigma2Ci[1]),
252+
kappa = data.frame(par="kappa",
253+
parName="\u03BA",
254+
estimate=1/sqrt(sigma2),
255+
se=1/sqrt(2*sigma2*seScale),
256+
lower=1/sqrt(sigma2Ci[2]),
257+
upper=1/sqrt(sigma2Ci[1]))
239258
)
240259

241260
results$structured <- rbind(loc, scale)

tests/testthat/test-ldgaussianunivariate.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,9 @@ test_that("Estimated Parameters table results match", {
7676
table <- results[["results"]][["mleContainer"]][["collection"]][["mleContainer_estParametersTable"]][["data"]]
7777
jaspTools::expect_equal_tables(table,
7878
list(0.130415109675896, -0.0510563552900477, "<unicode>", 0.0914574713318793,
79-
0.311886574641839, 0, 1, 0.836446906242152, 0.644813591445229,
80-
"<unicode><unicode>", "", 1.12877623260258))
79+
0.311886574641839, 0, 0.836446906242152, 0.644813591445229,
80+
"<unicode><unicode>", 0.0119486319092189, 1.12877623260258
81+
))
8182
})
8283

8384
test_that("Empirical vs. Theoretical CDF plot matches", {

0 commit comments

Comments
 (0)