similar to: sample(c(0, 1)...) vs. rbinom

Displaying 20 results from an estimated 10000 matches similar to: "sample(c(0, 1)...) vs. rbinom"

2008 May 28
"rbinom" not using probability of success right
I am trying to simulate a series of ones and zeros (1 or 0) and I am using "rbinom" but realizing that the number of successes expected is not accurate. Any advice out there. This is the example: N<-500 status<-rbinom(N, 1, prob = 0.15) count<-sum(status) 15 percent of 500 should be 75 but what I obtain from the "count" variable is 77 that gives the probability of
2012 Jan 03
nls and rbinom function: step factor 0.000488281 reduced below 'minFactor' of 0.000976562
I  am trying to learn nls using a simple simulation. I assumed that the binomial prob varies linearly as 0.2 + 0.3*x in  x {0,1}, and the objective is to recover the known parameters a=0.2, b=0.3 frame d has 1000 rows... d$x<-runif(0,1)               d$y<-rbinom(1000,1,0.2+0.3*d$x)  table(d$y,cut(d$x,breaks=5));   (-0.000585,0.199] (0.199,0.399] (0.399,0.599] (0.599,0.799]
2015 Mar 24
Hola de nuevo, ya empiezo a ser pesado ¿no? bueno, no importa porque aprendemos todos. Eso, al menos, me parece. Hoy estuve estudiando en R el tema de la aleatoriedad. Veo que hay múltiples posibilidades pero me están chocando mucho. Encuentro que el generador de números pseudo aleatorios es más pseudo de lo que debería. Me explico, quiero generar 0 y 1 aleatorios. Estoy trabajando con una
2007 Jul 06
How does the r-distribution function work
I am trying to understand what rbinom function does. Here is some sample code. Are both the invocations of bfunc effectively doing the same or I am missing the point? Thanks, Pieter bfunc <- function(n1,p1,sims) { c<-rbinom(sims,n1,p1) c } a=c() b=c() p1=.5 for (i in 1:10000){ a[i]=bfunc(30,p1,1) } b=bfunc(30,p1,10000)
2020 Oct 29
R: sim1000G
Hi, I am using the sim1000G R package to simulate data for case/control study. I can not figure out how to manipulate this code to be able to generate 10% or 50% causal SNPs in R. This is whole code provided as example on GitHub: library(sim1000G) vcf_file = "region-chr4-357-ANK2.vcf.gz" #nvariants = 442, ss=1000 vcf = readVCF( vcf_file, maxNumberOfVariants = 442 ,min_maf =
2011 Aug 26
How to find the accuracy of the predicted glm model with family = binomial (link = logit)
Hi All, When modeling with glm and family = binomial (link = logit) and response values of 0 and 1, I get the predicted probabilities of assigning to my class one, then I would like to compare it with my vector y which does have the original labels. How should I change the probabilities into values of zero and 1 and then compare it with my vector y to find out about the accuracy of my
2012 Jan 30
mgcv bam() with grouped binomial data
Hello, I'm trying to use the bam() function in the R mgcv package for a large set of grouped binary data. However, I have found that this function does not take data in the format of cbind(numerator, denominator) on the left hand side of the formula. As an example, consider the following dat1 <- data.frame(id=rep(1:6, each=3), num=rbinom(18, size=10, prob=0.8), den=rbinom(18, size=5,
2007 Jan 19
naive bayes help
Hello I have a rather simple code and for some reason it produces an error message. If someone can tell me why and how to fix it, I would be very greatful. Thank you in advance. ##### create data set.seed(10) n <- 200 # number of training points n.test <- 200 # number of test points p<-2 # dimension of input space z <-
2010 May 10
Random walk
Hi everybody, I am trying to generate two random walks with an specific correlation, for example, two random walks of 200 time steps with a correlation 0.7. I built the random walks with: x<-cumsum(rnorm(200, mean=0,sd=1)) y<-cumsum(rnorm(200, mean=0,sd=1)) but I don't know how to fix the correlation between them. With white noise is easy to fix the correlation using the function
2013 Jul 17
glmnet on Autopilot
Dear List, I'm running simulations using the glmnet package. I need to use an 'automated' method for model selection at each iteration of the simulation. The cv.glmnet function in the same package is handy for that purpose. However, in my simulation I have p >> N, and in some cases the selected model from cv.glmet is essentially shrinking all coefficients to zero. In this case,
2012 Aug 27
How to generate a matrix of Beta or Binomial distribution
Hi folks, I have a question about how to efficiently produce random numbers from Beta and Binomial distributions. For Beta distribution, suppose we have two shape vectors shape1 and shape2. I hope to generate a 10000 x 2 matrix X whose i th rwo is a sample from reta(2,shape1[i]mshape2[i]). Of course this can be done via loops: for(i in 1:10000) { X[i,]=rbeta(2,shape1[i],shape2[i]) } However,
2008 Sep 09
naive variance in GEE
Hi, The standard error from logistic regression is slightly different from the naive SE from GEE under independence working correlation structure. Shouldn't they be identical? Anyone has insight about this? Thanks, Qiong a<-rbinom(1000,1) b<-rbinom(1000,2,0.1) c<-rbinom(1000,10,0.5) summary(gee(a~b, id=c,family="binomial",corstr="independence"))$coef
2013 May 21
problem with "transform" and "get" functions
Hello, I'm having a problem using the "transform" and "get" functions. I'm probably making a dumb mistake, and I need help! I start by making a small simulated dataset. I save the names of the variables in "var.names." Without getting into the details of it, I have to create a custom function to perform some statistics. As part of this, I need to sequentially
2006 Apr 03
Does logistic regression require the independence of samples?
Dear list: Thanks a lot for help. I have a question and I could not find clear answers easily. When we do logistic regression for one type of events of interest as a proportion of a broader types of events, does the logistic regression assume that the number of whole types of events should be independent with the number of type of interest? For example, if one type of events and the whole type
1997 Jul 09
R-beta: Problem with `rpois'
There is a problem with `rpois'. It does seem to take care about the order of the arguments. This is an example: > rpois(n=1,lambda=2) [1] 3 > rpois(lambda=2,n=1) [1] 2 0 It obviously uses the first argument as the number of samples to be drawn, which is wrong. I used Version 0.49 Beta (April 23, 1997). Fredrik
1997 Jul 09
R-beta: Problem with `rpois'
There is a problem with `rpois'. It does seem to take care about the order of the arguments. This is an example: > rpois(n=1,lambda=2) [1] 3 > rpois(lambda=2,n=1) [1] 2 0 It obviously uses the first argument as the number of samples to be drawn, which is wrong. I used Version 0.49 Beta (April 23, 1997). Fredrik
2011 May 04
hurdle, simulated power
Hi all-- We are planning an intervention study for adolescent alcohol use, and I am planning to use simulations based on a hurdle model (using the hurdle() function in package pscl) for sample size estimation. The simulation code and power code are below -- note that at the moment the "power" code is just returning the coefficients, as something isn't working quite right. The
2001 Apr 08
Random Number Testing...
Hi, Suppose I want to test a set of random numbers (using the Binormal random number generator), input the following command to generate a set of random numbers: test <- rbinom( 10000000, 1, 0.5 ) How can I, after obtaining the result, export the vector "test" into an text file? Then, suppose I want to do something like: > x <- 1e10 > x [1] 1e+10
2006 Aug 23
glm inside one self-defined function
Hi list, I've searched in R-help and found some related discussions but still could not understand this type of error. My own function is pretty complex, so I would not put it here, but the basic algorithm is like this: myfun<-function(k){ mydata<-...#by someway I create a data frame mymodel<-glm(y~.,family=binomial(),data=mydata) ...#some other stuff } as I execute this
2006 Oct 09
testing for error
Dear R Helpers, I want to test if a procedure within a loop has produced an error or not. If the procedure has produced an error, then I want to ignore its result. If it has not produced an error, then I want to use the result. The problem In order to run the loop without crashing if the procedure produces an error, I place the routine inside a try() statement. So, suppose I am trying to find