Chapter 4 Introduction to Estimation
Example 4.1 Most people are right-handed, and even the right eye is dominant for most people. In a 2003 study reported in Nature, a German bio-psychologist conjectured that this preference for the right side manifests itself in other ways as well. In particular, he investigated if people have a tendency to lean their heads to the right when kissing. The researcher observed kissing couples in public places and recorded whether the couple leaned their heads to the right or left. (We’ll assume this represents a randomly representative selected sample of kissing couples.)
The parameter of interest in this study is the population proportion of kissing couples who lean their heads to the right. Denote this unknown parameter \(\theta\).
Let \(Y\) be the number of couples in a random sample of \(n\) kissing couples that lean to right. Then \(Y\) has a Binomial(\(n\), \(\theta\)) distribution. Suppose that in a sample of \(n=12\) couples \(y=8\) leaned to the right.
- If you were to estimate \(\theta\) with a single number based on this sample data alone, intuitively what number would you pick?
- For the next few parts suppose \(n=12\). For now we’ll only consider these potential values for \(\theta\): \(0.1, 0.3, 0.5, 0.7, 0.9\). If \(\theta=0.1\) what is the distribution of \(Y\)? Compute and interpret the probability that \(Y=8\) if \(\theta = 0.1\)
- If \(\theta=0.3\) what is the distribution of \(Y\)? Compute and interpret the probability that \(Y=8\) if \(\theta = 0.3\)
- If \(\theta=0.5\) what is the distribution of \(Y\)? Compute and interpret the probability that \(Y=8\) if \(\theta = 0.5\).
- If \(\theta=0.7\) what is the distribution of \(Y\)? Compute and interpret the probability that \(Y=8\) if \(\theta = 0.7\).
- If \(\theta=0.9\) what is the distribution of \(Y\)? Compute and interpret the probability that \(Y=8\) if \(\theta = 0.9\).
- Now remember that \(\theta\) is unknown. If you had to choose your estimate of \(\theta\) from the values \(0.1, 0.3, 0.5, 0.7, 0.9\), which one of these values would you choose based on of observing \(y=8\) couples leaning to the right in a sample of 12 kissing couples? Why?
- Obviously our choice is not restricted to those five values of \(\theta\). Describe in principle the process you would follow to find the estimate of \(\theta\) based on of observing \(y=8\) couples leaning to the right in a sample of 12 kissing couples.
- Let \(f(y|\theta)\) denote the probability of observing \(y\) couples leaning to the right in a sample of 12 kissing couples. Determine \(f(y=8|\theta)\) and sketch a graph of it. What is this a function of? What is an appropriate name for this function?
- What is our estimate of \(\theta\) based solely on the data of observing \(y=8\) couples leaning to the right in a sample of 12 kissing couples?
Show/hide solution
- Seems reasonable to use the sample proportion 8/12 = 0.667.
- If \(\theta=0.1\) then \(Y\) has a Binomial(12, 0.1) distribution and \(P(Y = 8|\theta = 0.1) = \binom{12}{8}0.1^8(1-0.1)^{12-8}\approx 0.000\);
dbinom(8, 12, 0.1)
. - If \(\theta=0.3\) then \(Y\) has a Binomial(12, 0.3) distribution and \(P(Y = 8|\theta = 0.3) = \binom{12}{8}0.3^8(1-0.3)^{12-8}\approx 0.008\);
dbinom(8, 12, 0.3)
. - If \(\theta=0.5\) then \(Y\) has a Binomial(12, 0.5) distribution and \(P(Y = 8|\theta = 0.5) = \binom{12}{8}0.5^8(1-0.5)^{12-8}\approx 0.121\);
dbinom(8, 12, 0.5)
. - If \(\theta=0.7\) then \(Y\) has a Binomial(12, 0.7) distribution and \(P(Y = 8|\theta = 0.7) = \binom{12}{8}0.7^8(1-0.7)^{12-8}\approx 0.231\);
dbinom(8, 12, 0.7)
. - If \(\theta=0.9\) then \(Y\) has a Binomial(12, 0.9) distribution and \(P(Y = 8|\theta = 0.9) = \binom{12}{8}0.9^8(1-0.9)^{12-8}\approx 0.021\);
dbinom(8, 12, 0.9)
. - Comparing the above, the probability of observing \(y=8\) is greatest when \(\theta=0.7\), so in some sense, the data seems most “consistent” with \(\theta=0.7\).
- For each value of \(\theta\) between 0 and 1 compute the probability of observing \(y=8\), \(P(Y = 8|theta)\), and find which value of \(\theta\) maximizes this probability.
- \(f(y|\theta)=P(Y=8|theta) = \binom{12}{8}\theta^8(1\theta)^{12-8}\). This is a function of \(\theta\), with the data \(y=8\) fixed. Since this function computes the likelihood of observing the data (evidence) under different values of \(\theta\), “likelihood function” seems like an appropriate name. See the plot below.
- The value which maximizes the likelihood of \(y=8\) is \(8/12\). So the maximum likelihood estimate of \(\theta\) is \(8/12\).
- For given data \(y\), the likelihood function \(f(y|\theta)\) is the probability (or density for continuous data) of observing the sample data \(y\) viewed as a function of the parameter \(\theta\).
- In the likelihood function, the observed value of the data \(y\) is treated as a fixed constant.
- The value of a parameter that maximizes the likelihood function is called a maximum likelihood estimate (MLE).
- The MLE depends on the data \(y\). For given data \(y\), the MLE is the value of \(\theta\) which gives the largest probability of having produced the observed data \(y\).
- Maximum likelihood estimation is a common frequentist technique for estimating the value of a parameter based on data from a sample.
Example 4.2 We’ll now take a Bayesian approach to estimating \(\theta\) in Example 4.1. We treat the unknown parameter \(\theta\) as a random variable and wish to find its posterior distribution after observing \(y=8\) couples leaning to the right in a sample of 12 kissing couples.
We will start with a very simplified, unrealistic prior distribution that assumes only five possible, equally likely values for \(\theta\): 0.1, 0.3, 0.5, 0.7, 0.9.
- Sketch a plot of the prior distribution and fill in the prior column of the Bayes table.
- Now suppose that \(y=8\) couples in a sample of size \(n=12\) lean right. Sketch a plot of the likelihood function and fill in the likelihood column in the Bayes table.
- Complete the Bayes table and sketch a plot of the posterior distribution. What does the posterior distribution say about \(\theta\)? How does it compare to the prior and the likelihood?
- Now consider a prior distribution which places probability 1/9, 2/9, 3/9, 2/9, 1/9 on the values 0.1, 0.3, 0.5, 0.7, 0.9, respectively. What does this prior distribution say about \(\theta\)? Redo the previous parts. How does the posterior distribution change?
- Now consider a prior distribution which places probability 5/15, 4/15, 3/15, 2/15, 1/15 on the values 0.1, 0.3, 0.5, 0.7, 0.9, respectively. What does this prior distribution say about \(\theta\)? Redo the previous parts. How does the posterior distribution change?
See plot below; the prior is “flat”.
The likelihood is computed as in Example 4.1.
See the Bayes table below. Since the prior is flat, the posterior is proportional to the likelihood.
# prior theta = seq(0.1, 0.9, 0.2) prior = rep(1, length(theta)) prior = prior / sum(prior) # data n = 12 # sample size y = 8 # sample count of success # likelihood, using binomial likelihood = dbinom(y, n, theta) # function of theta # posterior product = likelihood * prior posterior = product / sum(product) # bayes table bayes_table = data.frame(theta, prior, likelihood, product, posterior) kable(bayes_table, digits = 4, align = 'r')
theta prior likelihood product posterior 0.1 0.2 0.0000 0.0000 0.0000 0.3 0.2 0.0078 0.0016 0.0205 0.5 0.2 0.1208 0.0242 0.3171 0.7 0.2 0.2311 0.0462 0.6065 0.9 0.2 0.0213 0.0043 0.0559 # plots plot(theta-0.01, prior, type='h', xlim=c(0, 1), ylim=c(0, 1), col="orange", xlab='theta', ylab='') par(new=T) plot(theta+0.01, likelihood/sum(likelihood), type='h', xlim=c(0, 1), ylim=c(0, 1), col="skyblue", xlab='', ylab='') par(new=T) plot(theta, posterior, type='h', xlim=c(0, 1), ylim=c(0, 1), col="seagreen", xlab='', ylab='') legend("topleft", c("prior", "scaled likelihood", "posterior"), lty=1, col=c("orange", "skyblue", "seagreen"))
See table and plot below. Because the posterior probability is greater for 0.5 than for 0.7, the posterior probability of \(\theta=0.5\) is greater than in the previous part, and the posterior probability of \(\theta=0.7\) is less.
theta prior likelihood product posterior 0.1 0.1111 0.0000 0.0000 0.0000 0.3 0.2222 0.0078 0.0017 0.0181 0.5 0.3333 0.1208 0.0403 0.4207 0.7 0.2222 0.2311 0.0514 0.5365 0.9 0.1111 0.0213 0.0024 0.0247 See the table and plot below. The prior probability is large for 0.1 and 0.3, but since the likelihood corresponding to these values is so small, the posterior probabilities are small. This posterior distribution is similar to the one from the previous part.
theta prior likelihood product posterior 0.1 0.3333 0.0000 0.0000 0.0000 0.3 0.2667 0.0078 0.0021 0.0356 0.5 0.2000 0.1208 0.0242 0.4132 0.7 0.1333 0.2311 0.0308 0.5269 0.9 0.0667 0.0213 0.0014 0.0243
Bayesian estimation
- Regards parameters as random variables with probability distributions
- Assigns a subjective prior distribution to parameters
- Conditions on the observed data
- Applies Bayes’ rule to produce a posterior distribution for parameters \[ \text{posterior} \propto \text{likelihood} \times \text{prior} \]
- Determines parameter estimates from the posterior distribution
In a Bayesian analysis, the posterior distribution contains all relevant information about parameters. That is, all Bayesian inference is based on the posterior distribution. The posterior distribution is a compromise between
- prior “beliefs”, as represented by the prior distribution
- data, as represented by the likelihood function
In contrast, a frequentist approach regards parameters as unknown but fixed (not random) quantities. Frequentist estimates are commonly determined by the likelihood function.
It is helpful to plot prior, likelihood, and posterior on the same plot. Since prior and likelihood are probability distributions, they are on the same scale. However, remember that the likelihood does not add up to anything in particular. To put the likelihood on the same scale as prior and posterior, it is helpful to rescale the likelihood so that it adds up to 1. Such a rescaling does not change the shape of the likelihood, it merely allows for easier comparison with prior and posterior.
Example 4.3 Continuing Example 4.2. While the previous exercise introduced the main ideas, it was unrealistic to consider only five possible values of \(\theta\).
- What are the possible values of \(\theta\)? Does the parameter \(\theta\) take values on a continuous or discrete scale? (Careful: we’re talking about the parameter and not the data.)
- Let’s assume that any multiple of 0.0001 is a possible value of \(\theta\): \(0, 0.0001, 0.0002, \ldots, 0.9999, 1\). Assume a discrete uniform prior distribution on these values. Suppose again that \(y=8\) couples in a sample of \(n=12\) kissing couples lean right. Use software to plot the prior distribution, the (scaled) likelihood function, and then find the posterior and plot it. Describe the posterior distribution. What does it say about \(\theta\)?
- Now assume a prior distribution which is proportional to \(1-2|\theta-0.5|\) for \(\theta = 0, 0.0001, 0.0002, \ldots, 0.9999, 1\). Use software to plot this prior; what does it say about \(\theta\)? Then suppose again that \(y=8\) couples in a sample of \(n=12\) kissing couples lean right. Use software to plot the prior distribution, the (scaled) likelihood function, and then find the posterior and plot it. What does the posterior distribution say about \(\theta\)?
- Now assume a prior distribution which is proportional to \(1-\theta\) for \(\theta = 0, 0.0001, 0.0002, \ldots, 0.9999, 1\). Use software to plot this prior; what does it say about \(\theta\)? Then suppose again that \(y=8\) couples in a sample of \(n=12\) kissing couples lean right. Use software to plot the prior distribution, the (scaled) likelihood function, and then find the posterior and plot it. What does the posterior distribution say about \(\theta\)?
- Compare the posterior distributions corresponding to the three different priors. How does each posterior distribution compare to the prior and the likelihood? Does the prior distribution influence the posterior distribution?
The parameter \(\theta\) is a proportion, so it can possibly take any value in the continuous scale from 0 to 1.
See plot below. Since the prior is flat, the posterior is proportional to the likelihood. So the posterior distribution places highest posterior probability on values near the sample proportion 8/12.
# prior theta = seq(0, 1, 0.0001) prior = rep(1, length(theta)) prior = prior / sum(prior) # data n = 12 # sample size y = 8 # sample count of success # likelihood, using binomial likelihood = dbinom(y, n, theta) # function of theta # plots plot_posterior <- function(theta, prior, likelihood){ # posterior product = likelihood * prior posterior = product / sum(product) ylim = c(0, max(c(prior, posterior, likelihood / sum(likelihood)))) plot(theta, prior, type='l', xlim=c(0, 1), ylim=ylim, col="orange", xlab='theta', ylab='') par(new=T) plot(theta, likelihood/sum(likelihood), type='l', xlim=c(0, 1), ylim=ylim, col="skyblue", xlab='', ylab='') par(new=T) plot(theta, posterior, type='l', xlim=c(0, 1), ylim=ylim, col="seagreen", xlab='', ylab='') legend("topleft", c("prior", "scaled likelihood", "posterior"), lty=1, col=c("orange", "skyblue", "seagreen")) } plot_posterior(theta, prior, likelihood)
See plot below. The posterior is a compromise between the “triangular” prior which places highest prior probability near 0.5, and the likelihood. For this posterior, the posterior probability is greater near 0.5 than for the one in the previous part.
Again the posterior is a compromise between prior and likelihood. The prior probabilities are greatest for values of \(\theta\) near 0; however, the likelihood corresponding to these values is small, so the posterior probabilities are close to 0. As in the previous part, some of the posterior probability is shifted towards part 0.5, as opposed to what happens with the uniform prior.
For the “flat” prior, the posterior is proportional to the likelihood. For the other priors, the posterior is a compromise between prior and likelihood. The prior does have some influence. We do see three somewhat different posterior distributions corresponding to these three prior distributions.
- Even in situations where the data are discrete (e.g., binary success/failure data, count data), most statistical parameters take values on a continuous scale.
- Thus in a Bayesian analysis, parameters are usually continuous random variables, and have continuous probability distributions, a.k.a., densities.
- An alternative to dealing with continuous distributions is to use grid approximation: Treat the parameter as discrete, on a sufficiently fine grid of values, and use discrete distributions.
Example 4.4 Continuing Example 4.1. Now we’ll perform a Bayesian analysis on the actual study data in which 80 couples out of a sample of 124 leaned right. We’ll again use a grid approximation and assume that any multiple of 0.0001 between 0 and 1 is a possible value of \(\theta\): \(0, 0.0001, 0.0002, \ldots, 0.9999, 1\).
- Before performing the Bayesian analysis, use software to plot the likelihood when \(y=80\) couples in a sample of \(n=124\) kissing couples lean right, and compute the maximum likelihood estimate of \(\theta\) based on this data.
- Now back to Bayesian analysis. Assume a discrete uniform prior distribution for \(\theta\). Suppose that \(y=80\) couples in a sample of \(n=124\) kissing couples lean right. Use software to plot the prior distribution, the likelihood function, and then find the posterior and plot it. Describe the posterior distribution. What does it say about \(\theta\)?
- Now assume a prior distribution which is proportional to \(1-2|\theta-0.5|\) for \(\theta = 0, 0.0001, 0.0002, \ldots, 0.9999, 1\). Then suppose again that \(y=80\) couples in a sample of \(n=124\) kissing couples lean right. Use software to plot the prior distribution, the likelihood function, and then find the posterior and plot it. What does the posterior distribution say about \(\theta\)?
- Now assume a prior distribution which is proportional to \(1-\theta\) for \(\theta = 0, 0.0001, 0.0002, \ldots, 0.9999, 1\). Then suppose again that \(y=80\) couples in a sample of \(n=124\) kissing couples lean right. Use software to plot the prior distribution, the likelihood function, and then find the posterior and plot it. What does the posterior distribution say about \(\theta\)?
- Compare the posterior distributions corresponding to the three different priors. How does each posterior distribution compare to the prior and the likelihood? Comment on the influence that the prior distribution has. Does the Bayesian inference for these data appear to be highly sensitive to the choice of prior? How does this compare to the \(n=12\) situation?
See plot below. The likelihood function is \(f(y=80|\theta) = \binom{124}{80}\theta^{80}(1-\theta)^{124-80}, 0 \le\theta\le1\), the likelihood of observing a value of \(y=80\) from a Binomial(124, \(\theta\)) distribution (
dbinom(80, 124, theta)
). The maximum likelihood estimate of \(\theta\) is the sample proportion \(80/124=0.645\).See plot below. Since the prior is flat, the posterior is proportional to the likelihood. The posterior places almost all of its probability on \(\theta\) values between about 0.55 and 0.75, with the highest probability near the observed sample proportion of 0.645.
See the plot below. The posterior is very similar to the one from the previous part.
See the plot below. The posterior is very similar to the one from the previous part.
Even though the priors are different, they are all similar to each other and all similar to the shape of the likelihood. Comparing these priors it does not appear that the posterior is highly sensitive to choice of prior. The data carry more weight when \(n=124\) than it did when \(n=12\). In other words, the prior has less influence when the sample size is larger. When the sample size is larger, the likelihood is more “peaked” and so the likelihood, and hence posterior, is small outside a narrower range of values than when the sample size is small.
Recall that the likelihood function is the probability (or density for continuous data) of observing the sample data \(y\) viewed as a function of the parameter \(\theta\). When the data \(y\) takes values on a continuous scale, the likelihood is determined by the probability density function of \(Y\) given \(\theta\), \(f(y|\theta)\). In the likelihood function, the observed value of the data \(y\) is treated as a fixed constant, and the likelihood of observing that \(y\) is evaluated for all potential values of \(\theta\).
Recall that a continuous random variable11 \(U\) follows a Normal (a.k.a., Gaussian) distribution with mean \(\mu\) and standard deviation \(\sigma>0\) if its probability density function is12 \[\begin{align*} f_U(u) & = \frac{1}{\sigma\sqrt{2\pi}}\,\exp\left(-\frac{1}{2}\left(\frac{u-\mu}{\sigma}\right)^2\right), \quad -\infty<u<\infty.\\ & \propto \frac{1}{\sigma}\,\exp\left(-\frac{1}{2}\left(\frac{u-\mu}{\sigma}\right)^2\right), \quad -\infty<u<\infty. \end{align*}\] The constant \(1/\sqrt{2\pi}\) ensures that the total area under the density is 1, but it doesn’t effect the shape of the density.
In R, dnorm(u, mu, sigma)
.
Example 4.5 Assume body temperatures (degrees Fahrenheit) of healthy adults follow a Normal distribution with unknown mean \(\mu\) and known13 standard deviation \(\sigma=1\). Suppose we wish to estimate \(\mu\), the population mean healthy human body temperature.
- Assume first the following discrete prior distribution for \(\mu\) which places probability 0.10, 0.25, 0.30, 0.25, 0.10 on the values 97.6, 98.1, 98.6, 99.1, 99.6, respectively. Suppose a single temperature value of 97.9 is observed. Construct a Bayes table and find the posterior distribution of \(\mu\). In particular, how do you determine the likelihood?
- Now suppose a second temperature value, 97.5, is observed, independently of the first. Construct a Bayes table and find the posterior distribution of \(\mu\) after observing these two measurements, using the posterior distribution from the previous part as the prior distribution in this part.
- Now consider the original prior again. Determine the likelihood of observing temperatures of 97.9 and 97.5 in a sample of size 2. Then construct a Bayes table and find the posterior distribution of \(\mu\) after observing these two measurements. Compare to the previous part.
- Consider the original prior again. Suppose that we take a random sample of two temperature measurements, but instead of observing the two individual values, we only observe that the sample mean is 97.7. Determine the likelihood of observing a sample mean of 97.7 in a sample of size 2. (Hint: if \(\bar{Y}\) is the sample mean of \(n\) values from a \(N(\mu, \sigma)\) distribution, what is the distribution of \(\bar{Y}\)?) Then construct a Bayes table and find the posterior distribution of \(\mu\) after observing this sample mean. Compare to the previous part.
The likelihood is determined by evaluating the Normal(\(\mu\), 1) density at \(y=97.9\) for different values of \(\mu\):
dnorm(97.9, mu, 1)
or \[ f(97.9|\mu) = \frac{1}{\sqrt{2\pi}}\,\exp\left(-\frac{1}{2}\left(\frac{97.9-\mu}{1}\right)^2\right) \] See the table below. Posterior probability is shifted towards the smaller values of \(\mu\) since those give the higher likelihood of the observed value \(y=97.9\).# prior theta = seq(97.6, 99.6, 0.5) prior = c(0.10, 0.25, 0.30, 0.25, 0.10) prior = prior / sum(prior) # data y = 97.9 # single observed value sigma = 1 # likelihood likelihood = dnorm(y, theta, sigma) # function of theta # posterior product = likelihood * prior posterior = product / sum(product) # bayes table bayes_table = data.frame(theta, prior, likelihood, product, posterior) kable(bayes_table, digits = 4, align = 'r')
theta prior likelihood product posterior 97.6 0.10 0.3814 0.0381 0.1326 98.1 0.25 0.3910 0.0978 0.3400 98.6 0.30 0.3123 0.0937 0.3258 99.1 0.25 0.1942 0.0485 0.1688 99.6 0.10 0.0940 0.0094 0.0327 See the table below. More posterior probability is shifted towards the smaller values of \(\mu\).
# prior prior = posterior # data y = 97.5 # single observed value sigma = 1 # likelihood likelihood = dnorm(y, theta, sigma) # function of theta # posterior product = likelihood * prior posterior = product / sum(product) # bayes table bayes_table = data.frame(theta, prior, likelihood, product, posterior) kable(bayes_table, digits = 4, align = 'r')
theta prior likelihood product posterior 97.6 0.1326 0.3970 0.0527 0.2048 98.1 0.3400 0.3332 0.1133 0.4407 98.6 0.3258 0.2179 0.0710 0.2761 99.1 0.1688 0.1109 0.0187 0.0728 99.6 0.0327 0.0440 0.0014 0.0056 See the table below. Since the two measurements are independent, the likelihood is the product of the likelihoods for \(y=97.9\) and \(y=97.5\). The posterior is the same in the previous part. It doesn’t matter if we update the posterior after each observations, or all at once.
# prior theta = seq(97.6, 99.6, 0.5) prior = c(0.10, 0.25, 0.30, 0.25, 0.10) prior = prior / sum(prior) # data y = c(97.9, 97.5) # two observed values sigma = 1 # likelihood likelihood = dnorm(y[1], theta, sigma) * dnorm(y[2], theta, sigma) # function of theta # posterior product = likelihood * prior posterior = product / sum(product) # bayes table bayes_table = data.frame(theta, prior, likelihood, product, posterior) kable(bayes_table, digits = 4, align = 'r')
theta prior likelihood product posterior 97.6 0.10 0.1514 0.0151 0.2048 98.1 0.25 0.1303 0.0326 0.4407 98.6 0.30 0.0680 0.0204 0.2761 99.1 0.25 0.0215 0.0054 0.0728 99.6 0.10 0.0041 0.0004 0.0056 For a sample of size \(n\) from a \(N(\mu,\sigma)\) distribution, the sample mean follows a \(N\left(\mu, \frac{\sigma}{\sqrt{n}}\right)\) distribution. The likelihood is determined by evaluating the Normal(\(\mu\), \(\frac{1}{\sqrt{2}}\)) density at \(y=97.7\) for different values of \(\mu\):
dnorm(97.7, mu, 1 / sqrt(2))
or \[ f_{\bar{Y}}(97.7|\mu) \propto \exp\left(-\frac{1}{2}\left(\frac{97.7-\mu}{1/\sqrt{2}}\right)^2\right) \] See the table below. While the likelihood is not the same as in the previous part, it is proportionally the same; that is, the likelihood in this part has the same shape as the likelihood in the previous part. Therefore, the posterior distributions are the same.# prior theta = seq(97.6, 99.6, 0.5) prior = c(0.10, 0.25, 0.30, 0.25, 0.10) prior = prior / sum(prior) # data n = 2 y = 97.7 # sample mean sigma = 1 # likelihood likelihood = dnorm(y, theta, sigma / sqrt(n)) # function of theta # posterior product = likelihood * prior posterior = product / sum(product) # bayes table bayes_table = data.frame(theta, prior, likelihood, product, posterior) kable(bayes_table, digits = 4, align = 'r')
theta prior likelihood product posterior 97.6 0.10 0.5586 0.0559 0.2048 98.1 0.25 0.4808 0.1202 0.4407 98.6 0.30 0.2510 0.0753 0.2761 99.1 0.25 0.0795 0.0199 0.0728 99.6 0.10 0.0153 0.0015 0.0056
It is often not necessary to know all the individual data values to evaluate the shape of the likelihood as a function of the parameter \(\theta\), but rather simply the values of a few summary statistics.
For example, when estimating the population mean of a Normal distribution with known standard deviation \(\sigma\), it is sufficient to know the sample mean for the purposes of evaluating the shape of the likelihood of the observed data under different potential values of the population mean.
If \(Y_1, \ldots, Y_n\) is a random sample from a \(N(\mu, \sigma)\) distribution, then \(\bar{Y}\) has a \(N\left(\mu, \frac{\sigma}{\sqrt{n}}\right)\) distribution
- \(\sigma\) measures the unit-to-unit variability of individual values of the variable over all possible units in the population. For example, how much do body temperatures vary from person-to-person over many people?
- \(\frac{\sigma}{\sqrt{n}}\) measures the sample-to-sample variability of sample means over all possible samples of size \(n\) from the population. For example, how much do sample mean body temperatures from sample to sample over many samples of \(n\) people?
Example 4.6 Continuing the previous example. We’ll now use a grid approximation and assume that any multiple of 0.0001 between 96.0 and 100.0 is a possible value of \(\mu\): \(96.0, 96.0001, 96.0002, \ldots, 99.9999, 100.0\).
- Assume a discrete uniform prior distribution over \(\mu\) values in the grid. Suppose that the sample mean temperature is \(\bar{y}=97.7\) in a sample of \(n=2\) temperature measurements. Use software to plot the prior distribution, the (scaled) likelihood function, and then find the posterior and plot it. Describe the posterior distribution. What does it say about \(\mu\)?
- Now assume a prior distribution which is proportional to a Normal distribution with mean 98.6 and standard deviation 0.7 over \(\mu\) values in the grid. Suppose that the sample mean temperature is \(\bar{y}=97.7\) in a sample of \(n=2\) temperature measurements. Use software to plot the prior distribution, the (scaled) likelihood function, and then find the posterior and plot it. Describe the posterior distribution. What does it say about \(\mu\)?
- Compare the posterior distributions corresponding to the two different priors. How does each posterior distribution compare to the prior and the likelihood? Comment on the influence that the prior distribution has.
Since the prior is flat, the posterior has the same shape as the likelihood. The highest posterior probability is near the observed sample mean of 97.7.
# prior theta = seq(96, 100, 0.0001) prior = rep(1, length(theta)) prior = prior / sum(prior) # data n = 2 # sample size y = 97.7 # sample mean sigma = 1 # likelihood likelihood = dnorm(y, theta, sigma / sqrt(n)) # function of theta # plots plot_posterior <- function(theta, prior, likelihood){ # posterior product = likelihood * prior posterior = product / sum(product) ylim = c(0, max(c(prior, posterior, likelihood / sum(likelihood)))) plot(theta, prior, type='l', xlim=range(theta), ylim=ylim, col="orange", xlab='theta', ylab='') par(new=T) plot(theta, likelihood/sum(likelihood), type='l', xlim=range(theta), ylim=ylim, col="skyblue", xlab='', ylab='') par(new=T) plot(theta, posterior, type='l', xlim=range(theta), ylim=ylim, col="seagreen", xlab='', ylab='') legend("topleft", c("prior", "scaled likelihood", "posterior"), lty=1, col=c("orange", "skyblue", "seagreen")) } plot_posterior(theta, prior, likelihood)
Be sure to distinguish between the Normal distribution in the prior, which quantifies our prior uncertainty about \(\mu\), and the Normal distribution used to determine the likelihood which models variability of temperatures in the population. The poster is a compromise between likelihood and prior.
When the prior is flat, the posterior has the shape of the likelihood. Otherwise, the posterior is a compromise between prior and likelihood. When the sample size is so small, the prior will have a lot of influence on the posterior.
Example 4.7 Continuing the previous example. In a recent study14, the sample mean body temperature in a sample of 208 healthy adults was 97.7 degrees F.
We’ll again use a grid approximation and assume that any multiple of 0.0001 between 96.0 and 100.0 is a possible value of \(\mu\): \(96.0, 96.0001, 96.0002, \ldots, 99.9999, 100.0\).
- Before performing a Bayesian analysis, use software to plot the likelihood, and compute the maximum likelihood estimate of \(\mu\) based on this data.
- Assume a discrete uniform prior distribution over \(\mu\) values in the grid. Use software to plot the prior distribution, the (scaled) likelihood function, and then find the posterior and plot it. Describe the posterior distribution. What does it say about \(\mu\)?
- Now assume a prior distribution which is proportional a Normal distribution with mean 98.6 and standard deviation 0.7 over \(\mu\) values in the grid. Use software to plot the prior distribution, the (scaled) likelihood function, and then find the posterior and plot it. Describe the posterior distribution. What does it say about \(\mu\)?
- Compare the posterior distributions corresponding to the two different priors. How does each posterior distribution compare to the prior and the likelihood? Comment on the influence that the prior distribution has. How does this compare to the \(n=2\) situation?
The likelihood is determined by evaluating the Normal(\(\mu\), \(\frac{1}{\sqrt{208}}\)) density at \(y=97.7\) for different values of \(\mu\):
dnorm(97.7, mu, 1 / sqrt(208))
or \[ f_{\bar{Y}}(97.7|\mu) \propto \exp\left(-\frac{1}{2}\left(\frac{97.7-\mu}{1/\sqrt{208}}\right)^2\right) \] See a plot of the likelihood below. The MLE of \(\mu\) is the observed sample mean of 97.7.Since the prior is flat, the posterior has the same shape as the likelihood. With such a large sample size, the likelihood is pretty peaked. So the posterior probability is concentrated in a fairly narrow range of values around 97.7.
Even though the prior probability is highest near 98.6, the likelihood at these values is so small that they have small posterior probability. The posterior distribution is about the same as in the previous part.
The posterior distributions are about the same in each case. With a large sample size, the likelihood is fairly peaked, and so the likelihood is close to 0 outside of a narrow range of values around the observed sample mean of 97.7. Therefore, the posterior probability is concentrated in this range, regardless of the prior.
Why \(U\) and not \(X\) or \(Y\)? In a Bayesian analysis, we might assume the data follows a Normal distribution, but we might also use a Normal distribution to quantify the uncertainty about a parameter. We generally associate \(X\) and \(Y\) with data. \(U\) is supposed to represent a more general variable, which could be either data or a parameter.↩
\(\exp\) is just another way of writing the exponential function, \(\exp(u)=e^u\).↩
It’s unrealistic to assume the population standard deviation is known. We’ll consider the case of unknown standard deviation later.↩
Source and a related article.↩


EVO HTML to PDF Converter allows you select directly in HTML the elements to exclude from rendering to PDF by setting the data-exclude attribute on HTML elements you want to exclude.
The converter does not reflow the HTML content when you exclude an element from rendering and the place where the element would be normally rendered remains blank.
If you want to reflow the HTML content when the HTML element is hidden, you have to set display:none style for HTML element, eventually creating two separate stylesheets for screen and for print.
At the top of the demo you can choose the HTML document to convert which can be:
-
HTML Page to Convert URL. The URL must be accessible from the computer where the converter runs. If the page requires authentication or if you are using a proxy server to access Internet
then you have to set the converter properties accordingly as described in documentation
-
HTML String with Exclude Attributes. When you convert a HTML string you also have the option to specify a base URL that will be used
by converter to resolve the relative URLs found in the HTML string to fully qualified URLs. If your HTML string uses only fully qualified URLs then this parameter is not necessary


--- layout: page title: Hi, I'm Tejas Ruikar subtitle: Master's Student in Computer Science use-site-title: true ---
I am a 2nd-year Master's student in Computer Science at Arizona State University. My current interests are Machine Learning and Randomized Algorithms..
Before that, I obtained B.Tech degree in Information Technology department at COEP in 2016.
In past couple of years I had fortune to work with Amazon as a Software Developer Intern in Summer 2019 and at Credit Suisse,Pune as a Technology Analyst from August 2016 to July 2019.
Cluster Based Hierarchical Addressing for Dynamic Source Routing
[May 2019]I will join Amazon as a 2018 summber intern.
[July 2018]I will join Arizona State University for Master's in Computer Science for Fall 2019.
[December 2016] Paper published in Springers


Stockholm
feature films
short films
teatrical shorts
disney+
sparkshorts
cars toons
toy story toons
home entertainment
technology
renderman
graphic technologies
careers
careers at pixar
internships
life at pixar
events
extras
pixar in concert
art exhibition
pixar in a box
the science behind pixar
about
contact us
leadership
inclusion & outreach
coming soon
our story
company fac’s
careers at pixar
soul trailer
inclusion and outreach


| ↑ Blog |
So I set up a type system with general type inference and parametric polymorphism. One can already state such code:
function map[X,Y](a: List[X], f: X->Y): List[Y] let b = [] for x in a b.push(f(x)) end return b end let a = map(list(1..10), |x| 2*x) print(a)
Or this:
let compose = |g,f| |x| g(f(x)) let add = |x,y| x+y let h = compose(|x| add(x,1), |x| add(x,1)) print(h(0))
The type inference algorithm deduces:
compose: (Int->Int,Int->Int)->Int->Int add: (Int,Int)->Int h: Int->Int
One can also state compose
in polymorphic fashion:
function compose[X,Y,Z](g: Y->Z, f: X->Y): X->Z return |x| g(f(x)) end
Currently, there is no notion of mutability, because firstly this introduces a subtype relation and secondly I don't know whether it should become a first class feature of the type system or not. The type system and type checker will become more complex, one has to work out what the best algorithms would be.
Of course, reassignable variables are introduced with another
syntax – var
– instead of let
.
That's not the same as mutability, although both concepts are slightly
intertwined in Rust.
Regarding parametric polymorphism with type variables restricted by traits, a further complication emerges. Let's have a look at this code:
function pow[T: Mul+One](x: T, n: Int): T var y = T.one for k in 1..n y = y*x end return y end print(pow(2,10))
Here, pow
needs the type T
at runtime,
because it occurs explicitly in T.one
. One could obtain
it through x
, but in general this is not feasible
— for example, one cannot simply obtain the element type of
list, because the list could be empty, and an empty list does
not know its element type at runtime.
The best approach would be to give the type as an additional argument. The resulting code at runtime would be:
# impl One for Int Int.one = 1 function pow(x,n,T) y = T.one for k in 1..n y = y*x end return y end print(pow(2,10,Int))
This means, the ABI of a polymorphic function type would depend one the standalone occurrence of the type. Thus one must take care, this information is not erased during unification. It would be easier if the type argument is given explicitly for every type variable restricted by a trait.
Say we would like to code the generic map function. A first consideration would be:
List.zero = || [] Map.zero = || {} List.plus = fn|x| self.push(x); self end Map.plus = fn|x| self.add(x); self end map = |a,f| a.reduce(a.zero(), |b,x| b.plus(f(x)))
Now two problems arise. Firstly, there is monkey patching. Secondly, in Moss there is no separate type for sets. The above code will work for lists and sets, but not for maps.
A cleaner solution:
class Set = {} MapTrait = {} MapTrait[List] = table{ zero = || [], plus = fn|a,x| a.push(x); a end, iter = iter } MapTrait[Set] = table{ zero = || {}, plus = fn|s,x| s.add(x); s end, iter = iter } MapTrait[Map] = table{ zero = || {}, plus = fn|m,[k,v]| m[k] = v; m end, iter = |m| m.items() } function map(T,a,f) M = MapTrait[T] M.iter(a).reduce(M.zero(), |b,x| M.plus(b,f(x))) end print(map(List,[1,2,3,4],|x| 2*x)) print(map(Set,{1,2,3,4},|x| 2*x)) print(map(Map,{x=1,y=2},|[k,v]| [k,2*v]))
Would sets and maps have a different type, a simplification would be allowed:
MapTrait = {} MapTrait[List] = table{ zero = || [], plus = fn|a,x| a.push(x); a end } MapTrait[Set] = table{ zero = || {}, plus = fn|s,x| s.add(x); s end } MapTrait[Map] = table{ zero = || set{}, plus = fn|m,[k,v]| m[k] = v; m end } function map(a,f) M = MapTrait[type(a)] a.reduce(M.zero(), |b,x| M.plus(b,f(x))) end print(map([1,2,3,4],|x| 2*x)) print(map(set{1,2,3,4},|x| 2*x)) print(map({x=1,y=2},|[k,v]| [k,2*v]))
One may ask whether unification of map and set was a mistake. Anyway, the specific tasks may accomplished by iterator comprehensions, which are more general in certain ways.
print(list(2*x for x in [1,2,3,4])) print(set(2*x for x in {1,2,3,4})) print(map([k,2*v] for k,v in {x=1,y=2}.items()))
Until now f.orbit(x)
was defined like this:
function orbit(f,x) return fn|| y = x x = f(x) return y end end
This is actually wrong semantics. Say we have a function
next_perm(a)
, which returns the next permutation
of a list a
with regard to lexicographical order, but
works in-place and thus modifies a
itself. We would like
to generate all the permutations of an ordered list this way:
permutations = |a| next_perm.orbit(a).take(fac(len(a))) print(permutations([0,1,2]).map(copy).list())
As one can see, orbit
will eat up the first
permutation by calling f = next_perm
once before
returning y
. A second indication for the wrong semantics
is that f
is called once more than necessary.
The right behavior is
function orbit(f,x) first = true return fn|| if first first = false else x = f(x) end return x end end
or equivalently
function orbit(f,x) return fn*|| yield x x = f(x) end end


Reception of a New Tool
Lately I’ve been getting awesome feedback on my Internship Aggregate I launched at the end of summer. The students are telling faculty/staff in that unit how much they like the tool, how easy it is to use, etc. Basically they’re confirming the UX has been improved significantly since the original ColdFusion service launched. Best part is, I could scale the new architecture to serve the whole University basically overnight.
Here’s the kicker: The unit that requested it wanted it behind a login so no one outside their unit could use it or even see it. PSU bureaucracy at its finest.
Regardless, I’m very pleased with the application’s reception amongst its users. Feel free to fork the project on github.
Technical Overview
I was brought into this project by our lead programmer when the request was made for the update to an internship database. They were wanting an update to the look and feel of the site, essentially a UX overhaul. The old application was built in ColdFusion at around the turn of the century, so needless to say it in fact did need a huge facelift.
We decided to retain the backend “CMS” portion of the application and expose the content via a RESTful API. Once we got that working, I took the front-end and Joe (the other programmer) took updating the backend. We were able to work incredibly well since the my front-end design is only dependent upon the API. It was one of the most fluid front-end/backend collaborations I’ve experienced.
The RESTful API and CMS were built in, or remained in, ColdFusion while I used AngularJS as a front-end framework and Zurb Foundation for scaffolding.


CrimPapers
Articles published on 21 October 2018
On 21 October 2018, 3 new articles were published in 3 journals.
Preventing Juvenile Sexual Offending Through Parental Monitoring: A Comparison Study of Youth’s Experiences of Supervision by Kelly E. Stewart, Miranda H. Sitney, Keith L. Kaufman, Jonete Destefano, Thythy Bui
Innovation and Policing: Factors Influencing the Adoption of Social Medias By Members of Quebec Police Organizations
‘stealing the Fire’, 2.0 Style? Technology, the Pursuit of Mobility, Social Memory and De-Securitization of Migration by Sanja Milivojevic


...
Make some text that includes some html-entities in the tex, such as " < & > "
Try making another paragraph with a sub-header. Now, make a horisontal line
Next, make a table
| Header Column 1 | Header Coulumn 2 |
|---|---|
| Content Column 1 | Content Column 2 |
Finally, make a form


Now
What I'm doing now?
- Re-constructing this website. Entropy in action. My attempts of structuring my personal content may have come full circle.
This update was made on 11th January 2021.
What is this page?
This is a now page, and if you have your own site, you should make one too!
Inspiration for the "Now" page comes from Derek Sivers: https://sivers.org/now


Hi, I´m Vivi.
I am an aspiring web developer building web and mobile applications with passion. I love innovations, design, plants and pizza. Besides web development I have experience in SEO and product management. Feel free to contact me if you want to know more about me or have an idea what to build together.
Technologies, frameworks and tools I use.
JavaScript | HTML5 | CSS3 | mySQL | Node.js | mariaDB | React | Git | React-Native | ES6 | jQuery | Express | WordPress | Adobe Photoshop | TypeScript | Scrum | UX/UI


Cong is a Youtube blogger and His real name is Lincoln Velasquez and he is from the Philippines. He has a brother who's known as Junnie Boy; he's also a vlogger on YouTube.
Web Developer
Hes Currently Taking a Bachelors Degree of Computer Science at Cavite State University Silang Campus
Lorenz Umbay
BSCS-3B
Contact Me
Just leave a message and tell everything about my portfolio thank you.


We know who to hook you up with!
Great designs give life to your brand!
If they don't talk about you, do you really exist?
Started out in 2016 as we noticed a huge demand for new ways of marketing. The world is going more and more digital so we like to set the trends in that.
It all started with a little idea and a lot of hard work!
We added some services and next to doing only content creation we also started hooking up our clients with the best influencers, through our extended network we know 1000s of influential people who would love to get to know your brand.
Because of the huge demand of our services we had to hire a lot of new employees, because of this we moved offices and the real fun started, we dedicated to always deliver the best service to our clients on a daily basis
Lead Designer
Lead Marketer
Lead Developer


WABC hosts annual party for employees and their kids
by WABCUPPER WEST SIDE, New York (WABC) -- Santa Claus made a visit to ABC7NY.
He was one of the featured guests at the annual company party for the employees' kids.
WABC holds it the garage that ordinarily houses all those famous Eyewitness News vans.
The iconic blue vehicles were out of sight as the area transformed into an indoor carnival with all kinds of games and activities.


## andrew hunt, david thomas ### addison-wesley, 1999
summary
this is largely a book about the realities of being a programmer in a working-environment (mostly a business, profit-oriented one). still, it’s a well-rounded view of the life of software developers , and a series of heuristics which aren’t quite worried with the aesthetics/details of it, but rather with due process.
state that programming is a craft, and is about doing, not theories
programmer = listener (capture elusive requirements) + advisor + interpreter (express them so that the machine can do them justice) + dictator
this book is very much about the craft of programming (or so it claims) - early adopter/fast adapter (experience) - inquisitive (ask questions) - critical thinker (cf. above) - realistic - jack of all trades
even in business/corporate development, even in large teams, there is room for individuality. they claim that engineering and craftsmanship can coexist, this is visible in how emotional they are when talking about tools (p. 96, chap. 3)
kaizen: continuously making small improvements
yet another mention of the broken windows, coming from the fact that there is software that is just good enough (anti-craftsmanship?)
“don’t spoil a perfectly good program by overembellishment and over-refinement”
so it looks like the DRY acronym has been first presented in this book?
“no point in duplicating a comment in header and implementation files. put the comment on interface issues in the header file, and put the comment on details, nitty-gritty comment in the implementation files”
the trick is always about localization.
java
, c++
allow for accessor functions (e.g. getX(){ return x};
)
Yourdon and Constantine call the value of cohesion (self-contained, independent, single-clear-purpose)
no unknowns
no global data
plain-text: “human-readable forms of data will outlive all other forms of data and the applications that created them” > difference between human-readable and human-understandable
the IDE is still important as a tool, and def has an impact on style and aesthetics (auto-formatting)
liskov principle: “subclasses must be usable through the base class interface without the need for the user to know the difference”
poetics: you can use semantic invariants
to express inviolate requirements, a kind of “philosophical contract” » kind of like idempotency
the example on page 173 could be solved by a finally
the aesthetics of code is that everything is essential without ever being dependent on everything else —on nothing that it doesn’t need to know about —
decoupling is separating as much as possible
beautiful code is both soft (accomodates changes) and hard (does only one definite thing). being something while at the same time having the potentiality of being something else.
one example of why software is hard: temporal coupling. we don’t usually read in a TMEPORAL fashion so beautiful code is made to help us overcome hurdles such as these
when you’re coding, there are actually unexpected decisions that spring up unexpected all the time


JHipster Domain Language (JDL)
The JDL is a JHipster specific domain language where we have added the possibility to describe all your entities and their relationships in a single file (or more than one) with a simple and user-friendly syntax.
You can use our online JDL-Studio IDE to create JDL and its UML visualization. You can create and export or share URL of your JDL as well.
You can also generate entities from a JDL file using the import-jdl sub generator. Simply run yo jhipster:import-jdl yourJdlFilePath.jh
from the root of the generated JHipster application. Or by using JHipster UML.
- this can be used as a replacement to using the entity sub-generator. The idea is that it is much easier to manage relationships using a visual tool than with the classical Yeoman questions and answers.
The JDL project is available on Github, it is an Open Source project like JHipster (Apache 2.0 licence). This can be used a node library to do JDL parsing. If you like this project, don’t forget to give us a star on GitHub!
Here’s what’s covered on this page:
- JDL Sample
- How to use it
- The language
3.1 Entity Declaration
3.2 Relationship Declaration
3.3 Enumerations
3.4 Blobs
3.5 Option declaration
3.6 Microservice-related options - Commenting
- All the relationships
- Annexes
- Issues and bugs
JDL Sample
The Oracle example has been translated into JDL, and is available here. The same is loaded by default in JDL-Studio as well.
How to use it
You can use it by:
- simply creating a file with the extension ‘.jh’ or ‘.jdl’,
- declare your entities and relationships or create and download the file with JDL-Studio,
- in your JHipster application’s root folder, simply run
jhipster:import-jdl yourfile.jh
, - you can also use JDL files in JHipster UML with
jhipster-uml my_file.jdl
.
and Voilà, you are done!
If you work in a team, perhaps you would like to have multiple files instead of one. We added this option to JHipster UML so that you don’t manually
concatenate all the files into one, you just have to run jhipster-uml my_file1.jh my_file2.jh
.
If you want to use it in your project, you can add do so by doing npm install jhipster-domain-language --save
to install it locally, and save it in your package.json
file.
The language
We tried to keep the syntax as friendly as we can for developers.
You can do three things with it:
- Declare entities with their attributes,
- Declare the relationships between them,
- And declare some JHipster specific options.
Entity declaration
The entity declaration is done as follows:
entity <entity name> {
<field name> <type> [<validation>*]
}
<entity name>
is the name of the entity,<field name>
the name of one field of the entity,<type>
the JHipster supported type of the field,- and as an option
<validation>
the validations for the field.
The possible types and validations are those described here, if the validation requires a value, simply add (<value>)
right after the name of the validation.
Here’s an example of a JDL code:
entity A
entity B
entity C {}
entity D {
name String required,
address String required maxlength(100),
age Integer required min(18)
}
Because the JDL was made to be simple to use and read, if your entity is empty (no field), you can just declare an entity with entity A
or entity A {}
.
Note that JHipster adds a default id
field so that you don’t have to worry about it.
Relationship declaration
The relationships declaration is done as follows:
relationship (OneToMany | ManyToOne | OneToOne | ManyToMany) {
<from entity>[{<relationship name>}] to <to entity>[{<relationship name>}]
}
(OneToMany | ManyToOne| OneToOne | ManyToMany)
is the type of your relationship,<from entity>
is the name of the entity owner of the relationship: the source,<to entity>
is the name of the entity where the relationship goes to: the destination,<relationship name>
is the name of the field having the other end as type.
Here’s a simple example:
A Book has one Author, an Author has several Books.
entity Book
entity Author
relationship OneToMany {
Author{book} to Book{writer(name)}
}
Of course, in real cases, you’d have a lot of relationships and always writing the same three lines could be tedious.
That’s why you can declare something like:
entity A
entity B
entity C
entity D
relationship OneToOne {
A{b} to B{a},
B{c} to C
}
relationship ManyToMany {
A{d} to D{a},
C{d} to D{c}
}
By default, the joining is done by the id
field… But if you want the joining to be done by another field, then you can do things like:
entity A {
name String required
}
entity B
relationship OneToOne {
A{b} to B{a(name)}
}
Enumerations
To make Enums with JDL just do as follows:
-
Declare an Enum where you want in the file:
enum Language { FRENCH, ENGLISH, SPANISH }
-
In an entity, add fields with the Enum as a type:
entity Book { title String required, description String, language Language }
Blob (byte[])
JHipster gives a great choice as one can choose between an image type or any binary type. JDL lets you do the same: just create a custom type (see DataType) with the editor, name it according to these conventions:
AnyBlob
or justBlob
to create a field of the “any” binary type;ImageBlob
to create a field meant to be an image.
And you can create as many DataTypes as you like.
Option declaration
In JHipster, you can specify options for your entities such as pagination or DTO.
You can do the same with the JDL:
entity A {
name String required
}
entity B {}
entity C {}
dto A, B with mapstruct
paginate A, C with infinite-scroll
paginate B with pager
service A with serviceClass
service C with serviceImpl
The keywords dto
, paginate
, service
and with
were added to the grammar to support these changes.
If a wrong option is specified, JDL will inform you of that with a nice, red message and will just ignore it so as not to corrupt JHipster’s JSON files.
JDL also supports mass-option setting. it is possible to do:
entity A
entity B
...
entity Z
dto * with mapstruct
service all with serviceImpl
paginate C, with pager
Note that *
and all
are equivalent.
Latest version introduces exclusions (which is quite a powerful option when setting options for every entity):
entity A
entity B
...
entity Z
dto * with mapstruct except A
service all with serviceImpl except A, B, C
paginate C, with pager
With JHipster, you can also tell whether you don’t want any client code, or server code. Even if you want to add a suffix to Angular-related files, you can do that in JHipster.
In your JDL file, simply add these lines to do the same:
entity A
entity B
entity C
skipClient for A
skipServer for B
angularSuffix * with mySuperEntities
Finally, table names can also be specified (the entity’s name will be used by default):
entity A // A is the table's name here
entity B (the_best_entity) // the_best_entity is the table's name
Microservice-related options
As of JHipster v3, microservices can be created. You can specify some options to generate your entities in the JDL: the microservice’s name and the search engine.
Here is how you can specify your microservice’s name (the JHipster app’s name):
entity A
entity B
entity C
microservice * with mysuperjhipsterapp except C
microservice C with myotherjhipsterapp
search * with ElasticSearch except C
The first option is used to tell JHipster that you want your microservice to deal with your entities, whereas the second specifies how and if you want your entities searched.
Commenting & Javadoc
It is possible to add Javadoc & comments to JDL files.
Just like in Java, this example demonstrates how to add Javadoc comments:
/**
* Class comments.
* @author The JHipster team.
*/
entity MyEntity { // another form of comment
/** A required attribute */
myField String required,
mySecondField String // another form of comment
}
/**
* Second entity.
*/
entity MySecondEntity {}
relationship OneToMany {
/** This is possible too! */
MyEntity{mySecondEntity}
to
/**
* And this too!
*/
MySecondEntity{myEntity}
}
These comments will later be added as Javadoc comments by JHipster.
JDL possesses its own kind of comment:
// an ignored comment
/** not an ignored comment */
Therefore, anything that starts with //
is considered an internal comment for JDL, and will not be counted as Javadoc.
All the relationships
Explanation on how to create relationships with JDL.
One-to-One
A bidirectional relationship where the Car has a Driver, and the Driver has a Car.
entity Driver {}
entity Car {}
relationship OneToOne {
Car{driver} to Driver{car}
}
A Unidirectional example where a Citizen has a Passport, but the Passport has no access to sole its owner.
entity Citizen {}
entity Passport {}
relationship OneToOne {
Citizen{passport} to Passport
}
One-to-Many
A bidirectional relationship where the Owner has none, one or more Car objects, and the Car knows its owner.
entity Owner {}
entity Car {}
relationship OneToMany {
Owner{car} to Car{owner}
}
Unidirectional versions for this relationship are not supported by JHipster, but it would look like this:
entity Owner {}
entity Car {}
relationship OneToMany {
Owner{car} to Car
}
Many-to-One
The reciprocal version of One-to-Many relationships is the same as previously.
The unidirectional version where the Car knows its owners:
entity Owner {}
entity Car {}
relationship ManyToOne {
Car{owner} to Owner
}
Many-to-Many
Finally, in this example we have the Car that knows of its drivers, and the Driver object can access its cars.
entity Driver {}
entity Car {}
relationship ManyToMany {
Car{driver} to Driver{car}
}
Please note that the owning side of the relationship has to be on the left side
Annexes
Here is the types supported by JDL:
| SQL | MongoDB | Cassandra | Validations |
|---|---|---|---|
| String | String | String | required, minlength, maxlength, pattern |
| Integer | Integer | Integer | required, min, max |
| Long | Long | Long | required, min, max |
| BigDecimal | BigDecimal | BigDecimal | required, min, max |
| Float | Float | Float | required, min, max |
| Double | Double | Double | required, min, max |
| Enum | Enum | required | |
| Boolean | Boolean | Boolean | required |
| LocalDate | LocalDate | required | |
| Date | required | ||
| ZonedDateTime | ZonedDateTime | required | |
| UUID | required | ||
| Blob | Blob | required, minbytes, maxbytes | |
| AnyBlob | AnyBlob | required, minbytes, maxbytes | |
| ImageBlob | ImageBlob | required, minbytes, maxbytes |
Issues and bugs
JDL is available on Github, and follows the same contributing guidelines as JHipster.
Please use our project for submitting issues and Pull Requests concerning the library itself.
When submitting anything, you must be as precise as possible:
- One posted issue must only have one problem (or one demand/question);
- Pull requests are welcome, but the commits must be ‘atomic’ to really be understandable.


Chapter 7 Parametric tests and relevant assumptions
This section further illustrates assumptions of parametric tests and the methods to assess them.
7.1 Parametric statistical tests
T-test, analysis of variance, and linear regression are all parametric statistical tests. They are used when the dependent variable is an interval/ratio data variable, such as length, height, weight.
Advantages:
your audience will likely be familiar with the techniques and interpretation of the results.
These tests are also often more flexible and more powerful than their nonparametric analogues.
Drawback:
all parametric tests assume something about the distribution of the underlying data. If these assumptions are violated, the resultant test statistics will not be valid, and the tests will not be as powerful as for cases when assumptions are met.
Count/categorical data may not be appropriate for common parametric tests.
7.2 Assumptions
7.2.1 Random sampling
The data captured in the sample are randomly chosen from the population as a whole. Selection bias will obviously affect the validity of the outcome of the analysis.
7.2.2 Independent observations
Tests will also assume that observations are independent of one another, except when the analysis takes non-independence into account.
For example, in repeated measures experiments, the same subject is observed over time. Students with a high test score on one date to have a high test score on subsequent dates. In this case the observation on one date would not be independent of observations on other dates.The independence of observation is often assumed from good experimental design. Also, data or residuals can be plotted, for example to see if observations from one date are correlated to those for another date.
7.2.3 Normal distribution of data or residuals
Parametric tests assume that the data come from a population of known distribution, such as normal distribution. That is, the data are normally distributed once the effects of the variables in the model are taken into account.
Practically speaking, this means that the residuals from the analysis should be normally distributed. This will usually be assessed with a histogram of residuals, a density plot, or with quantile–quantile plot.
A select number of tests (limited to one-sample t-test, two-sample t-test, and paired t-test) will require that data itself be normally distributed.For other tests, the distribution of the residuals will be investigated.
Residuals, also commonly called errors, are the difference between the observations and the value predicted by the model. For example, if the calculated mean of a sample is 10, and one observation is 12, the residual for this observation is 2. Be careful not to get confused about this assumption. You may see discussion about how “data” should be normally distributed for parametric tests. This is usually wrong-headed. The t-test assumes that the observations for each group are normally distributed, but if there is a difference in the groups, we might expect a bi-modal distribution, not a simple normal distribution, for the combined data. This is why in most cases we look at the distribution of the residuals, not the raw data.
7.2.4 Homogeneity of variance
Parametric analyses will also assume a homogeneity of variance among groups. That is, for Student’s t-test comparing two groups, each group should have the same variance.Homogeneity of variance is also called homoscedasticity.
7.2.5 Additivity of treatment effects
Models for two-way analysis of variance and similar analyses are constructed as linear models in which the dependent variable is predicted as a linear combination of the independent variables.
A violation of this assumption is sometimes indicated when a plot of residuals versus predicted values exhibits a curved pattern.
7.2.6 Outliers
Outliers are observations whose value is far outside what is expected. They can play havoc with parametric analyses since they affect the distribution of the data and strongly influence the mean.
There are a variety of formal tests for detecting outliers, but they will not be discussed here. The best approach is one that looks at residuals after an analysis. Good tools are the “Residuals vs. leverage” plot and other plots in the “Other diagnostic plots” section below.
Some parametric tests are somewhat robust to violations of certain assumptions. For example, the t-test is reasonably robust to violations of normality for symmetric distributions, but not to samples having unequal variances (unless Welch’s t-test is used). A one-way analysis of variance is likewise reasonably robust to violations in normality.
…model assumptions should always be checked, but you may be able to tolerate small violations in the distribution of residuals or homoscedasticity. Large violations will make the test invalid, though. It is important to be honest with your assessments when checking model assumptions. It is better to transform data, change your model, use a robust method, or use a nonparametric test than to not have confidence in your analysis.
7.3 Assessing model assumptions
7.3.1 Normality of residuals
There are formal tests to assess the normality of residuals.
Common tests include
Shapiro-Wilk
Anderson–Darling
Kolmogorov–Smirnov
D’Agostino–Pearson
However, their results are dependent on sample size. When the sample size is large, the tests may indicate a statistically significant departure from normality, even if that departure is small. And when sample sizes are small, they won’t detect departures from normality.
In each case, the null hypothesis is that the data distribution is not different from normal. That is, a significant p-value (p < 0.05) suggests that data are not normally distributed.
# head(diamonds)
# summary(diamonds)
test_data = diamonds%>%
dplyr::filter(cut %in% c("Fair", "Ideal" ),
carat == 0.7,
color %in% c("G", "F" ),
clarity %in% c("SI1", "VS2" ))
# table(test_data$cut)
ggplot(test_data,
aes(price, fill = cut)) +
geom_density(position="dodge",
alpha = 0.6)
## Warning: Width not defined. Set with `position_dodge(width = ?)`
#Define a linear model
model = lm(price ~ cut + color,
data = test_data)
#Shapiro–Wilk normality test
x = residuals(model)
shapiro.test(x)
##
## Shapiro-Wilk normality test
##
## data: x
## W = 0.96048, p-value = 0.0006383
# Anderson-Darling normality test
# library(nortest)
x = residuals(model)
ad.test(x)
##
## Anderson-Darling normality test
##
## data: x
## A = 1.7123, p-value = 0.0002071
# One-sample Kolmogorov-Smirnov test
x = residuals(model)
ks.test(x,
"pnorm",
mean = mean(x),
sd = sd(x))
## Warning in ks.test(x, "pnorm", mean = mean(x), sd = sd(x)): ties should not
## be present for the Kolmogorov-Smirnov test
##
## One-sample Kolmogorov-Smirnov test
##
## data: x
## D = 0.096286, p-value = 0.1666
## alternative hypothesis: two-sided
# D'Agostino Normality Test
# library(fBasics)
x = residuals(model)
dagoTest(x)
##
## Title:
## D'Agostino Normality Test
##
## Test Results:
## STATISTIC:
## Chi2 | Omnibus: 10.2249
## Z3 | Skewness: 3.1412
## Z4 | Kurtosis: 0.5981
## P VALUE:
## Omnibus Test: 0.006021
## Skewness Test: 0.001683
## Kurtosis Test: 0.5498
##
## Description:
## Thu Dec 19 20:58:39 2019 by user: Juqiang Chen
7.3.2 Skew and kurtosis
There are no definitive guidelines as to what range of skew or kurtosis are acceptable for considering residuals to be normally distributed. we can rely on skew and kurtosis calculations,or histograms and other plots.
If the absolute value is > 0.5, BE CAUTIOUS If the absolute value is > 1.0, consider it not normally distributed. Some authors use 2.0 as a cutoff for normality, and others use a higher limit for kurtosis.
# library(psych)
x = residuals(model)
describe(x,
type=2)
## vars n mean sd median trimmed mad min max range skew
## X1 1 134 0 284.79 -40.84 -20.5 262.42 -543.69 839.01 1382.7 0.7
## kurtosis se
## X1 0.18 24.6
7.3.3 Visual inspection to assess the normality of residuals
Usually, the best method to see if model residuals meet the assumptions of normal distribution and homoscedasticity are to plot them and inspect the plots visually.
<IP_ADDRESS> Histogram with normal curve
A histogram of the residuals should be approximately normal, without excessive skew or kurtosis.
Adding a normal curve with the same mean and standard deviation as the data helps to assess the histogram.
x = residuals(model)
library(rcompanion)
plotNormalHistogram(residuals(model))
<IP_ADDRESS> Kernel density plot with normal curve
A kernel density plot is similar to a histogram, but is smoothed into a curve. Sometimes a density plot gives a better representation of the distribution of data, because the appearance of the histogram depends upon how many bins are used.
The plotNormalDensity function will produce this plot. Options include those for the plot function, as well as adjust, bw, and kernel which are passed to the density function. col1, col2, and col3 change plot colors, and lwd changes line thickness.
library(rcompanion)
x = residuals(model)
plotNormalDensity(x,
adjust = 1) ### Decrease this number
### to make line less smooth
7.3.4 Visual inspection for homogeneity of variance
Patterns in the plot of residuals versus fitted values can indicate a lack of homoscedasticity or that errors are not independent of fitted values.
plot(fitted(model),
residuals(model))
7.3.5 formal tests for homogeneity of variance
In each case, the null hypothesis is that the variance among groups is not different. That is, a significant p-value (p < 0.05) suggests that the variance among groups is different.
#Define a linear model
model = lm(price ~ cut + color,
data = test_data)
<IP_ADDRESS> Bartlett’s test for homogeneity of variance
Bartlett’s test is known to be sensitive to non-normality in samples. That is, non-normal samples can result in a significant test due to the non-normality.
x = residuals(model)
bartlett.test(x ~ interaction(cut, color),
data = test_data)
##
## Bartlett test of homogeneity of variances
##
## data: x by interaction(cut, color)
## Bartlett's K-squared = 39.068, df = 3, p-value = 1.679e-08
<IP_ADDRESS> Levene’s test for homogeneity of variance
Levene’s test is an alternative to Bartlett’s that is supposedly less sensitive to departures from normality in the data.
#library(car)
x = residuals(model)
leveneTest(x ~ cut * color,
data=test_data,
center=mean) ### original Levene’s test
## Levene's Test for Homogeneity of Variance (center = mean)
## Df F value Pr(>F)
## group 3 8.76 2.468e-05 ***
## 130
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
<IP_ADDRESS> Brown–Forsythe or robust Levene’s test
The Brown–Forsythe modification of Levene’s test makes it more robust to departures in normality of the data.
x = residuals(model)
#library(car)
leveneTest(x ~ cut * color, data=test_data)
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 3 8.5541 3.163e-05 ***
## 130
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#library(lawstat)
levene.test(x, interaction(test_data$cut, test_data$color))
##
## Modified robust Brown-Forsythe Levene-type test based on the
## absolute deviations from the median
##
## data: x
## Test Statistic = 0.51854, p-value = 0.6702
<IP_ADDRESS> Fligner-Killeen test
The Fligner-Killeen test is another test for homogeneity of variances that is robust to departures in normality of the data.
x = residuals(model)
fligner.test(x ~ interaction(cut, color), data=test_data)
##
## Fligner-Killeen test of homogeneity of variances
##
## data: x by interaction(cut, color)
## Fligner-Killeen:med chi-squared = 11.948, df = 3, p-value =
## 0.007562
References: https://rcompanion.org/handbook/I_01.html