KatInterview

Sampling a Logistic Variable and a Bivariate Chain

Statistics & ExperimentsModel answer
MediumModel answerStatistics & Experimentsinverse-transform-samplinggibbs-samplingmcmc

Last updated

Derive an inverse-CDF sampler for the logistic distribution, build a Gibbs sampler for a bivariate target, and explain how to check correctness, burn-in, thinning and sample size.

You need to generate random draws from two different targets using only a source of Uniform(0,1) random numbers and standard normal draws.

Part A. Produce samples from a Logistic distribution with location μ and scale s > 0.

  • Derive the quantile function (inverse CDF) and explain why it yields the right distribution.
  • Describe how you would confirm the generated sample is correct.
  • Mention numerical edge cases.

Part B. Produce samples from a bivariate density p(x, y) using Gibbs sampling. Assume a bivariate normal with means μx, μy, standard deviations σx, σy and correlation ρ.

  • Derive the full conditional distributions.
  • Write the sampler.
  • Explain how many draws you need, how much to discard as burn-in, and whether thinning helps.
  • Explain how you would detect that the chain has not converged.

State the general recipe for finding full conditionals when the joint density is not normal. Discuss what happens as |ρ| approaches 1.

Hints

Hint 1

For Part A, set u = F(x) and solve for x. The logistic CDF inverts cleanly into a log-odds expression, and you only need U to lie strictly inside (0,1).

Hint 2

For Part B, treat one variable as a constant in the joint density and complete the square. After standardizing, the X-chain of the Gibbs sampler is an AR(1) process, which gives you autocorrelations and an effective sample size.

Hint 3

For sample size, compare the target Monte Carlo error with sigma divided by the square root of the effective sample size, not the raw number of draws. Think about what discarding correlated draws does to the information you keep.