similar to: Loop avoidance in simulating a vector

Displaying 20 results from an estimated 20000 matches similar to: "Loop avoidance in simulating a vector"

2008 Jun 26
2
constructing arbitrary (positive definite) covariance matrix
Dear list, I am trying to use the 'mvrnorm' function from the MASS package for simulating multivariate Gaussian data with given covariance matrix. The diagonal elements of my covariance matrix should be the same, i.e., all variables have the same marginal variance. Also all correlations between all pair of variables should be identical, but could be any value in [-1,1]. The problem I am
2011 May 16
3
Simulating correlations with varying sample sizes
Hi there, I would like to draw 10 correlations from a bivariate population - but every draw should be done with a different sample size. I thought I could to this with a loop: r=numeric(10) #Goal vector N = c(1000,100,80,250,125,375,90,211,160,540) #Sample size vector for(i in 1:10) { data <- mvrnorm(n=N,mu=c(0,0),Sigma=matrix(c(1,.3,.3,1),2)) r[i] <- cor(data[,1],data[,2]) }
2009 Jun 03
1
Would like to add this to example for plotmath. Can you help?
Greetings: I would like comments on this example and after fixing it up, I need help from someone who has access to insert this in R's help page for plotmath. I uploaded a drawing http://pj.freefaculty.org/R/Normal-2009.pdf that is created by the following code http://pj.freefaculty.org/R/Normal1_2009_plotmathExample.R This will be a good addition to the plotmath help page/example.
2010 Jul 06
1
plotmath vector problem; full program enclosed
Here's another example of my plotmath whipping boy, the Normal distribution. A colleague asks for a Normal plotted above a series of axes that represent various other distributions (T, etc). I want to use vectors of equations in plotmath to do this, but have run into trouble. Now I've isolated the problem down to a relatively small piece of working example code (below). If you would
2012 Sep 11
1
Strange result from GAMLSS
Hi Folks! Just started using the gamlss package and I tried a simple code example (see below). Why the negative sigma? John > y <- rt(100, df=1)> m1<-fitDist(y, type="realline")Warning messages:1: In MLE(ll3, start = list(eta.mu = eta.mu, eta.sigma = eta.sigma, : possible convergence problem: optim gave code=1 false convergence (8)2: In MLE(ll4, start = list(eta.mu =
2008 Jul 23
1
R2WinBUGS problem
Dear friends - I'm on winXP, R 2.71 - I have with some help dveloped this multivariate normal model, which gives very plausible results in WinBUGS even without any initial values specified. However, when I then try to run the same model via the bugs function in R2WinBUGS with inits specified as inits=NULL the program stops in a dead end. So I have tried to make inits for the bugs function
2005 Mar 18
3
plotmath question
R listers: I have been foiled by plotmath! (in R 2.01,Windows 2000) The task: Plot a normal density and label the ticks as mu - 3 sigma, mu - 2 sigma, ...., mu + 3 sigma, where the mu's and sigmas appear as Greek symbols, of course. The following code does this: x<-seq(-3,to=3,by=.01) y<-dnorm(x) plot(x,y,type='h',col='lightblue',axes=FALSE)
2019 Dec 08
2
What should dnorm(0, 0, -Inf) return?
Yes, that looks like a bug and an easily fixable one too. However, I spy another issue: Why do we check the !R_FINITE(x) && mu == x before checking for sd < 0 ? The difference is whether we return ML_NAN; or ML_ERR_return_NAN; but surely negative sd should always be an error? I'd be inclined to do if (sigma < 0) ML_ERR_return_NAN; if(!R_FINITE(sigma)) return R_D__0;
2008 Apr 08
2
plotmath "overstrikes" in output on a Linux system
I've been testing plotmath. But I'm getting some funny output one one computer. The problem is that characters are 'jumbled' and overstrike when symbols are introduced. Sample code: mu <- 440.0 sigma <- 12.5 myx <- seq( mu - 4*sigma, mu+ 4*sigma, length.out=500) myDensity <- dnorm(myx,mean=mu,sd=sigma) # Here's one way to retrieve the values of mu and sigma and
2003 Aug 28
2
ks.test()
Dear All I am trying to replicate a numerical application (not computed on R) from an article. Using, ks.test() I computed the exact D value shown in the article but the p-values I obtain are quite different from the one shown in the article. The tests are performed on a sample of 37 values (please see "[0] DATA" below) for truncated Exponential, Pareto and truncated LogNormal
2005 Jun 22
1
legend
I color some area grey with polygon() (with a red border) and then I want to have the dashed red border in the legend as well. How do I manage it? And I want to mix (latex) expressions with text in my legend. Just execute my lines below and you know want I mean. Or pass by at http://de.wikipedia.org/wiki/Bild:GBM.png to see the picture online. Thomas bm <- function(n=500, from=0, to=1) {
2006 Aug 04
2
Doubt about Student t distribution simulation
Dear R list, I would like to illustrate the origin of the Student t distribution using R. So, if (sample.mean - pop.mean) / standard.error(sample.mean) has t distribution with (sample.size - 1) degree free, what is wrong with the simulation below? I think that the theoretical curve should agree with the relative frequencies of the t values calculated: #== begin options===== # parameters
2007 Apr 05
1
Plotting multiple curves with lattice graphs
Hi List, I would like to plot multiple curves (parametric density curves) in one plot. For example: # parameters for three normal density curves parms = data.frame(ID=c(1,2,3),mu=c(50,55,60),sigma=c(10,12,15)) # I can easily draw three normal density curves using curve(): curve(dnorm(x,mean=parms$mu[1],sd=parms$sigma[1]),from=0, to=150, ylab="density", col="red")
2009 Aug 07
1
Gauss-Laguerre using statmod
I believe this may be more related to analysis than it is to R, per se. Suppose I have the following function that I wish to integrate: ff <- function(x) pnorm((x - m)/sigma) * dnorm(x, observed, sigma) Then, given the parameters: mu <- 300 sigma <- 50 m <- 250 target <- 200 sigma_i <- 50 I can use the function integrate as: > integrate(ff, lower= -Inf, upper=target)
2005 Apr 05
2
Stats Question: Single data item versus Sample from Norma l Distribution
Here's one possibility, assuming muhat and sigmahat are estimtes of mu and sigma from N iid draws of N(mu, sigma^2): tStat <- abs(x - muhat) / sigmahat pValue <- pt(tStat, df=N, lower=TRUE) I'm not quite sure what df tStat should have (exercise for math stat), but given fairly large N, that should make little difference. Andy > From: Ross Clement > > Hi. I have a
2009 Sep 24
1
Fw: Re: Multiple Normal Curves
Sorry about the subject --- On Thu, 24/9/09, KABELI MEFANE <kabelimefane@yahoo.co.uk> wrote: From: KABELI MEFANE <kabelimefane@yahoo.co.uk> Subject: Re: [R] Multiply Normal Curves To: R-help@r-project.org Date: Thursday, 24 September, 2009, 11:48 AM R -helpers   i have been trying to do this problem without must success,i managed to do a graph for x, but it is not what i want to
2008 May 30
2
Including a tilde in a plotmath-type call
Suppose I have a plot plot(1:10, pch = "") And I want some text to indicate a Normal distrubition. I could do this: text(5, 6, substitute(X~~~~N(mu, sigma^2)), adj = 0) text(5.35, 6, "~", adj = 0) But that's clumsy, and depending on your plotting device, might not even look sensible. I'd prefer to be able to do it more directly and simply the way these do: text(5,
2012 Mar 22
2
Quicker way to apply values to a function
Hi all, myint=function(mu,sigma){ integrate(function(x) dnorm(x,mu,sigma)/(1+exp(-x)),-Inf,Inf)$value } mymu=seq(-3,3,length(1000)) mysigma=seq(0,1,length(500))[-1] k=1 v=c() for (j in 1:length(mymu)) { for (i in 1:length(mysigma)) { v[k]=myint(mymu[j],mysigma[i]) k=k+1 } } Basically, I want to investigate for what values of mu and sigma, the integral is divergent. Is there another way
2010 Jun 23
1
A question about R2Winbugs
Dear R users: I was trying to fit a HMM with mixture of Gaussian into the dataset, and I tried to implement it by R2Winbugs. But I got the following errer. * Error in FUN(X[[1L]], ...) : .C(..): 'type' must be "real" for this format* Does anybody know what's the problem? Does R2Winbugs accept some matrix as inits? I would really appreciate your help. Thank you very much.
2012 Mar 29
1
Error, Variable is Missing
Hi, I am writing a function to plot a pdf of a distribution, GNL.pdf.fn = function(x,mu,sigma,alpha,beta,rho) { y = x-rho*mu cf.fn = function(s){ cplex = complex(1,0,1) temp1 = alpha*beta*exp(-sigma*s^2/2) temp2 = (alpha-cplex*s)*(beta+cplex*s) out = (temp1/temp2)^rho out } temp.fn = function(s){ (Mod(cf.fn(s)))*cos(Arg(cf.fn(s))-s*y) } int.fn =