Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 630445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:51:20+00:00 2026-05-13T19:51:20+00:00

Suppose I have a bivariate discrete distribution, i.e. a table of probability values P(X=i,Y=j),

  • 0

Suppose I have a bivariate discrete distribution, i.e. a table of probability values P(X=i,Y=j), for i=1,…n and j=1,…m. How do I generate a random sample (X_k,Y_k), k=1,…N from such distribution? Maybe there is a ready R function like:

sample(100,prob=biprob)

where biprob is 2 dimensional matrix?

One intuitive way to sample is the following. Suppose we have a data.frame

dt=data.frame(X=x,Y=y,P=pij)

Where x and y come from

expand.grid(x=1:n,y=1:m)

and pij are the P(X=i,Y=j).

Then we get our sample (Xs,Ys) of size N, the following way:

set.seed(1000) 
Xs <- sample(dt$X,size=N,prob=dt$P)
set.seed(1000)
Ys <- sample(dt$Y,size=N,prob=dt$P)

I use set.seed() to simulate the “bivariateness”. Intuitively I should get something similar to what I need. I am not sure that this is correct way though. Hence the question 🙂

Another way is to use Gibbs sampling, marginal distributions are easy to compute.

I tried googling, but nothing really relevant came up.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T19:51:21+00:00Added an answer on May 13, 2026 at 7:51 pm

    You are almost there. Assuming you have the data frame dt with the x, y, and pij values, just sample the rows!

    dt <- expand.grid(X=1:3, Y=1:2)
    dt$p <- runif(6)
    dt$p <- dt$p / sum(dt$p)  # get fake probabilities
    idx <- sample(1:nrow(dt), size=8, replace=TRUE, prob=dt$p)
    sampled.x <- dt$X[idx]
    sampled.y <- dt$Y[idx]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

suppose we have this next sample code: while(some condition){ lock1.lock(); . . } the
Suppose I have a table MYtable as given below: ID A B C 1
Suppose I have the following table: PERSON : ID INT NAME STRING LASTNAME STRING
Suppose I have a module which defines some basic constants such as integer, parameter
Suppose we have a numbered circle. We want to go from point A to
Suppose I have a specific table selected in TinyMCE, like this: var ed =
Suppose I have a garden-variety closure like this bare-bones sample: (let ((alpha 0) #|
Suppose I have the following values:- xyz12@abc xyz1@abc xyz15@abc xyz2@abc xyz22@abc I want the
Suppose I have HTML like this, <table id=Words> <tr> <td class=cell>Hello</td> <td class=desc>A word</td>
Suppose i have one table that holds Blogs. The schema looks like : ID

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.