ashokkrish / CougarStats

5 stars 2 forks source link

Statistical Inference for One Population Standard Deviation: Confidence Interval #6

Closed ashokkrish closed 3 days ago

ashokkrish commented 6 months ago

@samantha-v-brian

When the user selects

image

Currently there are two parameters of interest to choose from

image

I would like to add another parameter of interest to this list and make it look like this

image

It can be achieved by the following code

                radioButtons(
                  inputId      = "popuParameter",
                  label        = strong("Parameter of Interest"),
                  choiceValues = list("Population Mean", 
                                      "Population Standard Deviation", 
                                      "Population Proportion"),
                  choiceNames  = list("Population Mean (\\( \\mu \\)) ", 
                                      "Population Standard Deviation (\\( \\sigma \\)) ", 
                                      "Population Proportion (\\( p\\))"),
                  selected     = "Population Mean", #character(0), #
                  inline       = FALSE), #,width = '1000px'),

Now suppose the user selects

image

We should have two numericInputs called

Sample Size (n) Population Standard Deviation (σ)

Validate the above two fields:

Next we will have a radio button toggle as follows

image

In the user selects Confidence Interval then display the following Confidence Level choices

image

In the user selects Hypothesis Testing then display the following

image

Followed by a numericInput for

Hypothesized Population Mean (σ0) Value

Following that have this

image
sam-vb commented 6 months ago

Hi Ashok! I've added the Population Standard Deviation radio button, as well as conditional panels for Sample Size (n) and Population Standard Deviation (σ). The conditional panels for Inference Types are both functioning per Mike Meyer's previous work.

Can you expand more on the Hypothesized Population Mean value? Additionally, is there a document I can refer to for sample values/formulas/calculations so I can test these new additions?

ashokkrish commented 6 months ago

@samantha-v-brian

Hi Sam,

Thanks for working on this issue. Here are some follow-up requests on this same issue.

Display the following messages

image image

On the mainPanel after all the validation checks out we will print the answer showing all the steps. For now if you can fix the above requests and push the code that'd great.

ashokkrish commented 6 months ago

For the radioButton could you set inline = FALSE? This will set the options as follows

image
sam-vb commented 6 months ago

Hi Ashok!

The above requests have been fixed. I also added main panel error messages for Sample Size Estimation per the task on Google Docs, as I'd missed them previously when implementing validation.

EDIT: commented just as you added the inline request! Will fix right now

EDIT: Fixed and pushed

ashokkrish commented 6 months ago

I am sorry about a minor confusion and it is entirely my fault,

In the radioButton choices it should be image (this needs a fix)

but the numericInput should be image (which is correct now)

In other words Population Standard Deviation is the Parameter of Interest and the Sample Standard Deviation is its point estimate.

sam-vb commented 6 months ago

Not a problem, it was an easy fix. I've pushed the change.

bryce-carson commented 1 month ago
image

These formulae need to be the radicand so that the standard deviation is calculated, not the variance (as depicted); right, @ashokkrish?

ashokkrish commented 1 month ago

@bryce-carson Yes, that's correct. Here is a another breakdown of steps,

image

Here is another fully worked out example

image
bryce-carson commented 1 month ago

@bryce-carson Yes, that's correct. Here is a another breakdown of steps,

image

Here is another fully worked out example

image

Those reference materials work perfectly for me. Thanks.

ashokkrish commented 1 month ago

@bryce-carson

Couple of examples to check the confidence interval results

image image
ashokkrish commented 1 month ago

@bryce-carson

I would the results displayed on the main panel in this sequence (I created this by patching a few screenshots into one)

image
bryce-carson commented 1 month ago

https://www.easysevens.com/understanding-chi-square-critical-value-a-beginners-tutorial/

This really helped me.

bryce-carson commented 1 month ago
image
* Don't need to bold the text "The confidence interval for σ is from"

For now it doesn't look exactly like that, but we will review it in the meeting.

bryce-carson commented 1 month ago

The results are now correct, however.

bryce-carson commented 1 month ago

The identifiers aren't the best.

ashokkrish commented 1 month ago

@bryce-carson

image

When alpha/2 is calculated you can round it to two-digits not three, e.g. 10% as 0.10 and not 0.100 5% as 0.05 and not 0.050. 1% as 0.01 and not 0.010.

However

0.05/2 should indeed be 0.025 (three digits) 0.01/2 should indeed be 0.005 (three digits).

bryce-carson commented 1 week ago

Returning to work on this tonight. Haven't done anything until now since we last spoke, @ashokkrish.

bryce-carson commented 5 days ago

@bryce-carson

image

When alpha/2 is calculated you can round it to two-digits not three, e.g. 10% as 0.10 and not 0.100 5% as 0.05 and not 0.050. 1% as 0.01 and not 0.010.

However

0.05/2 should indeed be 0.025 (three digits) 0.01/2 should indeed be 0.005 (three digits).

@ashokkrish, I do not understand the request for a change here. Your statements are conflicting; do you mean the right-hand side of the equation, the Chi-square test value, should be rounded to two digits? Why mention alpha / 2 at all? I'm sorry, but I'm too confused to move forward on just this. Can you elaborate, please?

ashokkrish commented 5 days ago

Why mention alpha / 2 at all?

We are constructing what is called as a two-sided confidence interval. This results in a lower confidence limit (LCL) and an upper confidence limit (UCL). I was simply being a little picky about the number of digits to display. Alpha is typically presented in two digits

10% as 0.10 and not 0.100 5% as 0.05 and not 0.050. 1% as 0.01 and not 0.010.

whereas

0.05/2 should indeed be 0.025 (three digits) 0.01/2 should indeed be 0.005 (three digits).

Does this help?

bryce-carson commented 5 days ago

@ashokkrish What I will do for this issue otherwise is ensure that the user-provided values are displayed with the phrasing, "Given n, s, ..." et cetera before the calculations.

ashokkrish commented 5 days ago

@ashokkrish What I will do for this issue otherwise is ensure that the user-provided values are displayed with the phrasing, "Given n, s, ..." et cetera before the calculations.

Follow the exact same format we used for confidence interval for population mean (mu) and population proportion (p).

bryce-carson commented 5 days ago

Why mention alpha / 2 at all?

We are constructing what is called as a two-sided confidence interval. This results in a lower confidence limit (LCL) and an upper confidence limit (UCL). I was simply being a little pick about the number of digits to display.

Alpha is typically presented in two digits

10% as 0.10 and not 0.100 5% as 0.05 and not 0.050. 1% as 0.01 and not 0.010.

whereas

0.05/2 should indeed be 0.025 (three digits) 0.01/2 should indeed be 0.005 (three digits).

Does this help?

Oh! Yeah, that helps a lot. I'll reduce the digits of the alpha to two digits, so it displays like below. Is this right?

$$ \chi^2{1-\alpha/2} = \chi^2{1-0.05/2} = \chi^2_{0.975} $$

rather than

$$ \chi^2{1-\alpha/2} = \chi^2{1-0.050/2} = \chi^2_{0.975} $$

With the same change for the other side of the confidence interval.

bryce-carson commented 5 days ago

@ashokkrish What I will do for this issue otherwise is ensure that the user-provided values are displayed with the phrasing, "Given n, s, ..." et cetera before the calculations.

Follow the exact same format we used for confidence interval for population mean (mu) and population proportion (p).

Will do!

ashokkrish commented 5 days ago

I'll reduce the digits of the alpha to two digits, so it displays like below. Is this right?

This is perfect.

bryce-carson commented 5 days ago

@ashokkrish, I have just pushed a commit which changes the formatting to what you desired. Please let me know if it is sufficient and I will close the issue.

bryce-carson commented 5 days ago

@ashokkrish I will begin working on #33 now.

ashokkrish commented 5 days ago

@ashokkrish, I have just pushed a commit which changes the formatting to what you desired. Please let me know if it is sufficient and I will close the issue.

@bryce-carson

If you look at the confidence interval for one population mean (mu) when sigma is unknown you will notice the following

image

Clarify alpha = 1 - 0.90/0.95/0.99 = 0.10/0.05/0.01

Same way, I would like you to embed the df in the subscripts of the calculations of

image
ashokkrish commented 5 days ago

@bryce-carson

image

Left indent this and add a break between the rows.

ashokkrish commented 5 days ago

@bryce-carson

image image

The confidence level here must be expressed as 90%/95%/99%.

Replace the word lies with is.

bryce-carson commented 4 days ago

I'm working on these tasks now, @ashokkrish. At the end of my day I'll let you know what progress I've made on #33. I fully expect all of these tasks to be completed within an hour or so, depending on how much trouble the align environment gives me.

ashokkrish commented 4 days ago

@bryce-carson

This is excellent. I look forward to testing the new code.

bryce-carson commented 4 days ago

@ashokkrish, I have completed this work. Please see the pushed updated. I will begin work on #33 now.

ashokkrish commented 4 days ago
image

@bryce-carson

Could you bring the CI = outside the parentheses?

Give a space after the comma.

ashokkrish commented 4 days ago

@bryce-carson

image

Drop the word where and move the df calculation below alpha calculation. So something like this

image

newline

image

newline

image
bryce-carson commented 4 days ago

@ashokkrish How is it now? If you'd like further spacing between the lower and upper CIs I can use \quad instead of \;\:.

ashokkrish commented 4 days ago

@bryce-carson The spacing and CI workflow looks good.

I just encountered a validation bug. The sample size n must be greater than 1 (>1). However as it stands with the following numbers the resulting CI produces NaNs.

image image

Can you check and fix this please?

ashokkrish commented 4 days ago

@bryce-carson Follow-up to the above bug. When the user enters

image

Now click Calculate you will see

image

on the main panel.

Further if the user enters

image

Now click Calculate you will see

image

Clearly there is a conditional panel exception that is skipping some but not all validation.

bryce-carson commented 4 days ago

@ashokkrish, interesting. I'll look at those validation issues.

bryce-carson commented 4 days ago

@ashokkrish, I have fixed this issue.

bryce-carson commented 4 days ago

conditional panel exception

A conditionalPanel controls visibility based on a condition, while a shinyvalidate input validation object uses a boolean function and a set of rules to test the validity of an input widget's data. They're separate concerns and concepts, just to refresh your memory.

ashokkrish commented 4 days ago

@bryce-carson

When the user enters

image

The app crashes with this error

image

Warning: Error in sprintf: invalid format '%d'; use format %f, %e, %g or %a for numeric objects 101: sprintf 97: renderUI [C:\Users\ashok\Desktop\CougarStatsApp\CougarStats\R\statInfr.R#4757] 96: func 83: renderFunc 82: output$si-oneSDCI 1: shiny::runApp

If you look at inference for one population mean (mu) you will notice there is an extra layer of instant validation on non-integer sample size entries.

image
bryce-carson commented 4 days ago

@bryce-carson

When the user enters

image

The app crashes with this error

image

Warning: Error in sprintf: invalid format '%d'; use format %f, %e, %g or %a for numeric objects 101: sprintf 97: renderUI [C:\Users\ashok\Desktop\CougarStatsApp\CougarStats\R\statInfr.R#4757] 96: func 83: renderFunc 82: output$si-oneSDCI 1: shiny::runApp

If you look at inference for one population mean (mu) you will notice there is an extra layer of instant validation on non-integer sample size entries.

image

Thanks, I will get that done tomorrow morning.