Displaying 20 results from an estimated 3000 matches similar to: "Generate multivariate normal data with a random correlation matrix"
2011 Oct 18
1
Repeat a loop until...
Dear all,
I know there have been various questions posted over the years about loops but I'm afraid that I'm still stuck. I am using Windows XP and R 2.9.2.
I am generating some data using the multivariate normal distribution (within the 'mnormt' package). [The numerical values of sanad and covmat are not important.]
> datamat <-
2008 Oct 02
3
Adding plane in a 3D scatterplot
I have drawn a 3D scatter plot :
library(mnormt)
library(scatterplot3d)
dat = cbind(rmnorm(3, rep(0,2), diag(2)), 1:3)
scatterplot3d(dat)
Now I want to do 2 things :
1 : In the Z-axis (i.e. height), I want to see only numbers 1,2,3, etc NOT, 1,1.5,2,2.5.............
2. I want to add two Horizontal planes at hight z=2 and z=3. Those two planes should look like "bottom" of that 3D plot
2006 Dec 11
2
Switch and integer
I searched the help list and the manual, but I do not find my mistake.
Switch is working with character , with integer, but not in the third
example
Regards Knut
count1 <- 0
test
2010 Feb 18
1
an error about " return some vectors from some functions within a function"
Dear all,
When I try to return some vectors from some functions within a function, it indicate an error," Error in rbind(ck1, ck2, ck3) : object 'ck1' not found", in one of the iterations and stop. Since I am not experienced in programming, can anyone give me a suggestion to inspect this error?
The followings are the functions I created :
###################
# functions in the
2008 Jul 22
1
scatter plot using ggplot
I used ggplot to create a scatter plot :
library(ggplot)
library(mnormt)
Sigma = matrix(c(1, 0.6, 0.6, 1), 2, 2)
x = rmnorm(20, c(0,0), Sigma)
xx = x[order(x[,1]),]
y = xx[,1]
z = xx[,2]
qplot(z, y, type="point", main="x-y plot", xlab="x", col="blue")
However I want following:
1. Plot color must be Blue (where it is displaying as red)
2. There should not
2012 Jul 11
3
Subset based on multiple values
I'm stuck on a seemingly simple problem. I'm trying to subset the data by
several numbers and it cuts out half of the rows. Here is the sample code:
test <- as.matrix(c(1,1,1,1,3,3,7,7,7,7))
Count <- tapply(test[,1], test[,1], length) # count for each value
spp <- unique(test[,1])
Count1 <- as.data.frame(cbind(Count,spp))
Max <- max(Count)
Count1$sppMax <-
2002 Jan 15
1
acf conf intervals +speed
Hi,
I'm trying to obtain confidence intervals for auto and
cross correlation estimates. I've adapted code made
available by Stock and Watson that uses the Bartlett
Kernel and the delta method. In R it runs really,
really slow because of the loops it uses and I have 9
series that I'd like to examine (81 total
combinations). It was easy enough to replace one of
the while loops with a
2017 Aug 28
5
"Improvement with the R code"
Hello,
I am trying to implement a formula
aij= transition from state S_i to S_j/no of transition at state S_i
Code I have written is working with three state {1,2,3 }, but if the number
of states become={1,2,3,4,......n} then the code will not work, so can some
help me with this.
For and some rows of my data frame look like
2010 Dec 02
2
Hmisc label function applied to data frame
Hello,
I'm attempting to create a data frame with correlations between every pair
of variables in a data frame, so that I can then sort by the value of the
correlation coefficient and see which pairs of variables are most strongly
correlated.
The sm2vec function in the corpcor library works very nicely as shown here:
library(Hmisc)
library(corpcor)
# Create example data
x1 = runif(50)
x2 =
2017 Aug 28
0
"Improvement with the R code"
Hi,
I think you overthought this one a little bit, I don't know if this is the
kind of code you are expecting but I came up with something like that:
generate_transition_matrix <- function(data, n_states) {
#To be sure I imagine you should check n_states is right at this point
transitions <- matrix(0, n_states, n_states)
#we could improve a little bit here because at
2009 May 15
2
Using column length in plot gives error
Hi
I'm trying to write a generic script for processing some data which finishes
off with some plots. Given Im never sure how many columns will be in my
dataframe I wanted to using the following
plot(spectra.wavelength, cormat, type = "l", ylim=c(-1,1), xlab="Wavelength
(nm)", ylab="Correlation")
however even if I specify as type="l" it appears plot
2004 Jul 07
1
Histograms, density, and relative frequencies
R-users,
I have been using R for about 1 year, and I have run across a
couple of graphics problem that I am not quite sure how to address. I have
read up on the email threads regarding the differences between density and
relative frequencies (count/sum(count) on the R list, and I am hoping that
someone could provide me with some advice/comments concerning my
approach. I will admit
2013 Feb 20
1
Problem with levelplot() in a loop
Dear R users,
I am trying to print heatmaps in a loop (with a pause). Idea is to
visualize changing correlations over time and for testing I wrote this
simple (reproducible) code below.
My problem is that levelplot() does not produce any output when I run the
code (though heatmap does). Ideally I would like to use levelplot() as it
produces a neat index on the side indicating the color and the
2009 Oct 29
1
operation with if/else on a dataframe
Hi to all,
I have this dataframe (I show the first six rows)
>head(table)
A R Fold.Change P.Value
Count1 Count2
1 ENSRNOE00000000002_at 0 1.13 0.60 1
1
2 ENSRNOE00000000009_at 0 -1.04 0.73 3
3
3 ENSRNOE00000000020_at 0 -1.08
2001 Mar 16
1
combine dataset
Hi,
I have two data sets look like below:
==========================
state count1 percent1
CA 19 0.34
TX 22 0.35
FL 11 0.24
OR 34 0.42
GA 52 0.62
MN 12 0.17
NC 19 0.34
state count2 percent2
FL 22 0.35
MN 22 0.35
CA 11 0.24
TX 52 0.62
==========================
How to combine these two data set and make it look
like below?
2011 May 05
1
matrix not positive definite (while it should be)
I do have some trouble with matrices. I want to build up a covariance matrix
with a hierarchical structure). For instance, in dimension n=10, I have two
subgroups (called REGION).
NR=2; n=10
CORRELATION=matrix(c(0.4,-0.25,
-0.25,0.3),NR,NR)
REGION=sample(1:NR,size=n,replace=TRUE)
R1=REGION%*%t(rep(1,n))
R2=rep(1,n)%*%t(REGION)
SIGMA=matrix(NA,n,n)
for(i in 1:NR){
for(j in
2009 Feb 11
2
Loop on characters
Hi,
suppose I have three vectors like :
l1 = 1:4
l2 = 4:9
l3 = 16:67
now I want to construct a loop like :
for (i in 1:3)
{
count1[i] = length(li) # i.e. it will take l1, l2, l3 according to
value of i
}
Can anyone please tell me how to do that?
Regards,
--
View this message in context: http://www.nabble.com/Loop-on-characters-tp21949173p21949173.html
Sent from the R help
2009 Oct 14
1
using mapply to avoid loops
Hello, I would like to use mapply to avoid using a loop but for some reason, I can't seem to get it to work. I've included copies of my code below. The first set of code uses a loop (and it works fine), and the second set of code attempts to use mapply but I get a "subscript out of bounds" error. Any guidance would be greatly appreciated. Xj, Yj, and Wj are also lists, and s2,
2002 Jun 18
3
FINDNEXT problem, w2k and linux smbfs
I have inconsistent directory listing on share mounted on linux from windows 2k.
Some time not all files appear in the directory listing.
If reading directory listing multiple times (60-200 times) files listed originally would have one or two files missing in one of consecutive lists. The same problem appear as well if you are making backup of Windows files from multiple directories, there are
2008 May 17
1
Correlated Columns in data frame
Dear all,
Sorry to post my query once again in the list, since I did
not get attention from anyone in my previous mail to this
list.
Now I make it simple here that please give me a code for
find out the columns of a dataframe whose correlation
coefficient is below a pre-determined threshold. (For
detailed query please see my previous message to this list,
pasted hereunder)
Thanks and regards,