search for: rchisq

Displaying 20 results from an estimated 84 matches for "rchisq".

Did you mean: chisq
2005 Dec 13
8
superimpose density line over hist
Hi all, I'm trying to superimpose a rchisq density line over a histogram with something like: hist(alnlength) lines(density(rchisq(length(alnlength), 4)),col="red") But the rchisq line won't appear anywhere, Anyone knows what I am missing here? Thanks in advance, Albert.
2006 Jul 01
1
noncentral F-distributed random numbers (PR#9055)
...5) The QQ-plot of two versions of simulating noncentral F-distributed random numbers has quite different scales: > qqplot(rf(1000,2,15,3),qf(runif(1000),2,15,3)) The rf() function reads: > rf function (n, df1, df2, ncp = 0) { if (ncp == 0) .Internal(rf(n, df1, df2)) else rchisq(n, df1, ncp = ncp)/rchisq(n, df2) } <environment: namespace:stats> where I believe both the numerator and the denominator should be divided by their corresponding degrees of freedom. My suggested (slighly augmented) version is: > rf= function (n, df1, df2, ncp1 = 0, ncp2=0) { if (...
2010 Aug 17
2
plotting functions of chi square
Hi! This is going to be a real newbie question, but I can't figure it out. I'm trying to plot densities of various functions of chi-square. A simple chi-square plot I can do with dchisq(). But e.g. chi.sq/degrees of freedom I only know how to do using density(rchisq()/df). For example: plot(1, type="n", xlab="", ylab="", xlim=c(0,2), ylim=c(0,7)) for (i in c(10,50,100,200,500)){ lines(density(rchisq(100000,i)/i)) } But even with 100,000 samples the curves still aren't smooth. Surely there must be a more elegant way to do t...
2012 Nov 13
1
Simulation with cpm package
...for (cm in 1:length(changeMagnitudes)) { for (cl in 1:length(changeLocations)) { print(sprintf("cpm:%s magnitude::%s location:%s", cpmType, changeMagnitudes[cm], changeLocations[cl])) temp <- numeric(sims) for (s in 1:sims) { x <-c(rchisq(changeLocations[cl], df=3), rchisq(2000, df=changeMagnitudes[cm])) temp[s] <-detectChangePoint(x, cpmType, ARL0=ARL0, startup=startup)$detectionTime } results[[cpmType]][cm,cl] <- mean(temp[temp > changeLocations[cl]]) - chan...
2010 Nov 07
3
Integrate and mapply
...s matter. The code is below. The function needed to be integrated (undint with respect to u from 0 to Inf). Sincerely, V. Code rm=list(ls()) #index matrix t1<-c(1:15) t2<-c(1:5)%x%matrix(1,3,1) t3<-matrix(1,3,1)%x%c(1:5) t4<-c(1:3)%x%matrix(1,5,1) comb<-cbind(t1,t2,t3,t4) nu<-rchisq(15,4) gam<-matrix(rchisq(75,df=5),15,5) undint<-function(u){ prob<-function(i) { i1<-comb[i,1] i2<-comb[i,2] i3<-comb[i,3] i4<-comb[i,4] val1<-gam[((i3-1)*2+1):(i3*2),i4] vc1<-matrix(12,length(val1),1)-matrix(u,length(val1),1)-val1 distr1<-prod(pchisq(vc1,df=2)) p1...
2006 Dec 19
3
Bug in rt() ? (PR#9422)
...t(n = 1000, df = 20) set.seed(12345) t.2 <- rt(n = 1000, df = 20, ncp = 0) all.equal(t.1, t.2) ## Not close to true This appears to be due to the fact that in 2.4.x rt is now rt function (n, df, ncp = 0) { if (missing(ncp)) .Internal(rt(n, df)) else rnorm(n, ncp)/sqrt(rchisq(n, df)/df) } <environment: namespace:stats> Whereas in 2.3.1 rt() is verified to work as expected when someone (redundantly) types ncp = 0 rt function (n, df, ncp = 0) { if (ncp == 0) .Internal(rt(n, df)) else rnorm(n, ncp)/(rchisq(n, df)/sqrt(df)) } <environment: namespace:st...
2002 Jun 13
3
Bug in rnorm. (PR#1664)
...<- function(n,mu=0,sigma=1){ mu + sigma*cos(2*pi*runif(n))*sqrt(-2*log(runif(n))) } which uses the ``(r,theta)'' method of generating random normals. When I did so, the resulting values were indeed all ``close to'' 0.05, as they should be. I also tried the experiment using rchisq(n,1) instead of rnorm(n) (and then of course taking m = max of x --- rather than max of x^2). Again all the resulting values were close to 0.05 as ought to be the case. (So rchisq() appears to be OK in this regard.) Enclosed below is a script to demonstrate the bug. cheers, Rolf Turn...
2008 Oct 20
2
folded normal distribution in R
Dear R useRs, i wanted to ask if the folded normal destribution (Y = abs(X) with X normal distributed) with density and random number generator is implemented in R or in any R-related package so far? Maybe i can use the non-central chi-square distribution and rchisq(n, df=1, ncp>0) here? Thanks and best regards Andreas
2010 Aug 16
1
lm prediction strange error
Dear all, I have an error in the simple prediction function for lm(). Maybe someone experienced the same? xma <- matrix(data = 0, nrow = 100, ncol = 2) xma[, 1] <- rnorm(100) xma[, 2] <- rchisq(100, df = 3) m1 <- lm(xma[, 1] ~ xma[, 2]) predict(m1, as.data.frame(seq(-13, 13, 0.5))) Thanks a lot, Trafim [[alternative HTML version deleted]]
2012 Nov 30
3
protentially serious R error
...#####case 4######### *> b<-1-0.8 > rnorm(20*b) [1] 0.9101742 0.3841854 1.6821761* I was expecting the 4 cases should do the same job--generate 4 random numbers. But in case 2 and 4 I only get 3. Has anyone else seen this problem before? Thanks. (I have tried with other functions i.e "rchisq","rexp" ...) ####################################################################### One of my colleague also have a problem that we think it might be related with the problem I addressed above: > test1 <- runif(10,0,1) > test1 [1] 0.3868379 0.1587814 0.8140483 0.7796691 0...
2008 Jul 08
4
Histogram with colors according to factor
Given a data frame with a continuous variable and a factor. I would like to generate a histogram of the continuous variable, where each bar is filled with different colors according to the percentage of factor values falling into this region of the continuous variable. I looked into packages like 'lattice' and 'ggplot2'. Searching R-help revealed that 'histogram' is
1997 Jul 09
1
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
1
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
2006 Jul 20
1
Loss of numerical precision from conversion to list ?
...+00 4.00000e+00 4.00000e+00 4.00000e+00 4.00000e+00 4.00000e+00 4.00000e+00 #[21] 4.00000e+00 4.00000e+00 4.00000e+00 4.00000e+00 4.00000e+00 4.00000e+00 5.77316e-15 # ! Notice the last (27th) value very close to 0 nsim<-10 set.seed(10) #nsim x K array of ChiSq(1)-variates w.k.sq.mat<-matrix(rchisq(nsim*K,1),nrow=nsim) #nsim x 1 array of ChiSq(n-p-K)-variates w.sum2<-rchisq(nsim,n-p-K) ### vectorized computation of nsim=10 realizations ### of a part of the RLR-statistic under the Null: w.k.sq<- cbind(w.k.sq.mat,w.sum2) #nsim x (K+1) #vector-based results: nu...
2006 Jun 30
1
Random numbers from noncentral t-distribution
Hi there: I'd thought these two versions of noncentral t-distribution are essentially the same: > qqplot(rt(1000,df=20,ncp=3),qt(runif(1000),df=20,ncp=3)) But, the scales of the x-axis and the y-axis are quite different according to the QQ-plot. Did I make any mistakes somewhere? Thanks, Long ---------------------------------
2006 Nov 02
2
simulation with "rpois"
Hi there, I need some helpo with one simulation. I have a matrix of 4x21 I want ro generate 100 random Chi2 distribution but inly from the first row of my matrix. This is what I try: Option (a): >lambda=1:100 >f=function(x)chisq(4,0,x) >lapply(lambda,f) It doesn't work! option(b): >m=mean(matrix[1,]) >x<-rpois(100,lambda=m) Works, but only generates a row of 25 values.
2010 Nov 30
1
rcauchy density distribution
Hello, I'm taking samples from certain distributions and drawing a density distribution over the histogram of the samples It works fine for the chi-square and for the normal, but not for the cauchy. Any idea what I'm doing wrong? Thanks x <- rchisq(10000, df = 4) hist(x, freq = FALSE, breaks=100) curve(dchisq(x, df = 4), col = 2, add = TRUE) x <- rnorm(10000) hist(x, freq = FALSE, breaks=100) curve(dnorm(x), col = 2, add = TRUE) x <- rcauchy(10000) hist(x, freq = FALSE, breaks=100) curve(dcauchy(x), col = 2, add = TRUE) [[a...
2012 Dec 04
3
monte carlo simulation on R
Hello, How can I make a monte carlo simulation on R? Regards Adel -- PhD candidate in Computer Science Address 3 avenue lamine, cité ezzahra, Sousse 4000 Tunisia tel: +216 97 246 706 (+33640302046 jusqu'au 15/6) fax: +216 71 391 166 [[alternative HTML version deleted]]
2002 Oct 25
1
Quantil-quantile plot help
Dear list I am using the qq.plot command to create quantile-quantile plots. The plot should display a 45 degree reference line upon which the points of the graph should fall if the two distributions being examined are roughly equal. If I try: x<-rchisq(100, df=6) qq.plot(x, dist="chisq", df=6) Then I get a quantile plot which has an intercept of roughly 1 when the line should be going through (0,0)? Could someone explain why this is happening on this plot and how I can get what I need? Many thanks Laura -.-.-.-.-.-.-.-.-.-.-.-.-.-....
2007 May 20
2
section needed in FAQ - Using R (PR#9698)
...e are too many hits for "Random" and they dive too deeply. My answer to this FAQ would be: In order to generate random numbers, there are "r" methods for every distribution. Distributions include Uniform (runif), Binomial (rbinom), Normal (rnorm), Cauchy (rcauchy), Chi Square (rchisq), Exponential (rexp), Gamma (rgamma), and many more. By the way, the R program itself is really badly in need of an "appropos()" to go alongside "help()". Perhaps "help()" can be renamed to "hunt()" or "huntAndPeck()".