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 5969623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:15:24+00:00 2026-05-22T20:15:24+00:00

I´m trying to simulate death over 7 years with the cumulative probability as follows:

  • 0

I´m trying to simulate death over 7 years with the cumulative probability as follows:

tab <- data.frame(id=1:1000,char=rnorm(1000,7,4))

cum.prob <- c(0.05,0.07,0.08,0.09,0.1,0.11,0.12)

How can I sample from tab$id without replacement in a vectorized fashion according to the cumulative probability in cum.prob ? The ids sampled from yr 1 can necessarily not be sampled again in yr 2. Hence the lapply(cum.prob,function(x) sample(tab$id,x*1000)) will not work. Is it possible to vectorize this?

//M

  • 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-22T20:15:24+00:00Added an answer on May 22, 2026 at 8:15 pm

    Here’s one way: First get the probability of a given individual’s dying in a given year as probYrDeath, i.e. probYrDeath[i] = Prob( individual dies in year i ), where i=1,2,...,7.

    probYrDeath <- c(diff(c(0,cum.prob)).
    

    Now generate a random sample of 1000 “Death Years”, with replacement, from the sequence 1:8, according to the probabilities in probYrDeath, augmented by the probability of not dying by year 7:

    set.seed(1) ## for reproducibility
    tab$DeathYr <- sample( 8, 1000, replace = TRUE, 
                           prob = c(probYrDeath, 1-sum(probYrDeath)))
    

    We interpret “‘DeathYr = 8′” as “not dying within 7 years”, and extract the subset of tab where DeathYr != 8:

    tab_sample <- subset(tab, DeathYr != 8 )
    

    You can verify that the cumulative proportions of deaths in each year approximate the values in cum.prob:

    > cumsum(table(tab_sample$DeathYr)/1000)
        1     2     3     4     5     6     7 
    0.045 0.071 0.080 0.094 0.105 0.115 0.124 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to simulate an actual tab key press in JavaScript. I don't want
i am trying to simulate the pressing of the TAB key. I have search
I am trying to simulate a scenario where connection to the server of one
I am trying to simulate linux command ls using linux api from c. Looking
I'm currently trying to simulate holding a key down for a specified time. The
I'm trying to simulate rotating box using Newton Physics and OpenGL. This is what
I am trying to simulate a simple MIPS processor using behavior code in Verilog.
I am trying to simulate the interface of mobile (ios / android)... Drag the
I have a 32GB memory machine and I want to simulate trying out one
I'm trying to define a way to simulate an case on accessing into a

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.