• + 0 comments
    import math
    
    def b_from_correlation_formula(r_squared, std_x, std_y):
        corr = math.sqrt(r_squared)
        b_x = corr * std_y / std_x
        return b_x
    
    def b_from_covariance_formula(r_squared, std_x, std_y):
        corr = math.sqrt(r_squared)
        cov_xy = corr * std_x * std_y
        b_x = cov_xy / (std_x ** 2)
        return b_x
    
    method = 0
        
    if method == 0:
        b_x = b_from_correlation_formula(0.4, 4, 8)
    else:
        b_x = b_from_covariance_formula(0.4, 4, 8)
           
    
    print(f'{b_x:.2f}')