Skip to content

Instantly share code, notes, and snippets.

View koushikkhan's full-sized avatar

Koushik Khan koushikkhan

View GitHub Profile
ln.object <- LogNormalSimulator$new(mu = 5, sigma = 0.5, n_sample = 100000)
ln.sample <- test$generate_lognormal_sample()
ln.object$compute_stats()
LogNormalSimulator <- R6Class("LogNormalSimulatorClass",
inherit = GaussianSimulator,
public = list(
log_normal_sample = NA,
initialize = function(mu, sigma, n_sample) {
super$initialize(mu = mu, sigma = sigma, n_sample = n_sample)
},
generate_lognormal_sample = function() {
normal_sample <- self$generate_sample()
# Usage of the class
# 1. create a new object of the class named `sm`
sm <- GaussianSimulator$new(mu=165, sigma=6.6, n_sample=1000)
# 2. generate a random sample
r <- sm$generate_sample()
# 3. compute basic ststistics of the sample
basic.stats <- sm$compute_stats()
# A class to generate sample from Gaussian Distribution
# mean, standard-deviation and sample size are being
# expected to come from the user
library(R6)
library(ggplot2)
GaussianSimulator <- R6Class("GaussianSimulatorClass",
public = list(
mu = NA,
5.1,3.5,1.4,0.2,Iris-setosa
4.9,3.0,1.4,0.2,Iris-setosa
4.7,3.2,1.3,0.2,Iris-setosa
4.6,3.1,1.5,0.2,Iris-setosa
5.0,3.6,1.4,0.2,Iris-setosa
5.4,3.9,1.7,0.4,Iris-setosa
4.6,3.4,1.4,0.3,Iris-setosa
5.0,3.4,1.5,0.2,Iris-setosa
4.4,2.9,1.4,0.2,Iris-setosa
4.9,3.1,1.5,0.1,Iris-setosa