File size: 2,061 Bytes
e88c533
14c55f0
 
 
f4eeec3
14c55f0
 
 
 
 
 
1664ae3
14c55f0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1664ae3
14c55f0
 
1664ae3
14c55f0
 
 
1664ae3
14c55f0
 
e88c533
14c55f0
 
 
e88c533
14c55f0
 
e88c533
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import streamlit as st
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import norm
from streamlit_lottie import st_lottie
import requests

# Function to load Lottie animations
def load_lottie_url(url: str):
    response = requests.get(url)
    if response.status_code != 200:
        return None
    return response.json()

# Title of the app
st.title("Probability and Statistics Explorer")

# Load and display Lottie animation
lottie_url = "https://assets4.lottiefiles.com/packages/lf20_4ueuj8wi.json"  # Replace with your own Lottie URL
lottie_animation = load_lottie_url(lottie_url)
st_lottie(lottie_animation, speed=1, width=None, height=None, key="animation")

# Sidebar for user input
st.sidebar.header("User Input")

# Mean and standard deviation input
mean = st.sidebar.number_input("Mean (μ)", value=0.0)
std_dev = st.sidebar.number_input("Standard Deviation (σ)", value=1.0)

# Generate values for the normal distribution
x = np.linspace(mean - 4 * std_dev, mean + 4 * std_dev, 1000)
y = norm.pdf(x, mean, std_dev)

# Plot the normal distribution
plt.figure(figsize=(10, 5))
plt.plot(x, y, label='Normal Distribution', color='blue')
plt.title('Normal Distribution Curve')
plt.xlabel('Value')
plt.ylabel('Probability Density')
plt.grid()
plt.legend()
st.pyplot(plt)

# Probability calculations
st.sidebar.header("Probability Calculations")

# Input for cumulative probability
probability_input = st.sidebar.number_input("Calculate P(X ≤ x)", value=0.0)

# Calculate cumulative probability
cumulative_prob = norm.cdf(probability_input, mean, std_dev)
st.sidebar.write(f"P(X ≤ {probability_input}) = {cumulative_prob:.4f}")

# Input for percentile
percentile_input = st.sidebar.number_input("Calculate Percentile (x)", value=0.0)

# Calculate percentile
percentile_value = norm.ppf(percentile_input, mean, std_dev)
st.sidebar.write(f"{percentile_input * 100}th Percentile = {percentile_value:.4f}")

# Show the app
st.write("This app allows you to explore the normal distribution and perform basic probability calculations.")