Class: NormalDistribution::Model

Inherits:
Object
  • Object
show all
Defined in:
lib/normal_distribution/model.rb,
ext/normal_distribution/normal_distribution.c

Instance Method Summary collapse

Constructor Details

#initialize(values) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
# File 'ext/normal_distribution/normal_distribution.c', line 64

static VALUE t_init( VALUE self, VALUE values ) {
	long size;
	double * data = t_parse_dbl_ary( values, &size );
	double mean = t_mean( data, size );
	double stddev = t_stddev( data, size, mean );

	rb_iv_set( self, "@mean", rb_float_new( mean ) );
	rb_iv_set( self, "@standard_deviation", rb_float_new( stddev ) );
	free( data );

	return self;
}

Instance Method Details

#confidence_interval(percentage) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'ext/normal_distribution/normal_distribution.c', line 77

static VALUE t_confidence_interval( VALUE self, VALUE percentage ) {
    double perc = t_parse_percentage( percentage );
	double z = t_z_score( perc );
	double stddev = NUM2DBL( rb_iv_get( self, "@standard_deviation" ) );
	double mean = NUM2DBL( rb_iv_get( self, "@mean" ) );
	double lower_bound = - z * stddev + mean;
	double upper_bound = z * stddev + mean;

	VALUE pair = rb_ary_new();
	rb_ary_push( pair, rb_float_new( lower_bound ) );
	rb_ary_push( pair, rb_float_new( upper_bound ) );

	return pair;
}

#meanObject



92
93
94
# File 'ext/normal_distribution/normal_distribution.c', line 92

static VALUE t_attr_mean( VALUE self ) {
	return rb_iv_get( self, "@mean" );
}

#standard_deviationObject



96
97
98
# File 'ext/normal_distribution/normal_distribution.c', line 96

static VALUE t_attr_stddev( VALUE self ) {
	return rb_iv_get( self, "@standard_deviation" );
}