search for: cut2

Displaying 20 results from an estimated 35 matches for "cut2".

Did you mean: cut
2013 Feb 01
2
Nested loop and output help
...5,10,by=1) for(i in n) { z1 <- rnorm(n,mean=400, sd=70) z2 <- rnorm(n,mean=450, sd=90) cor <- runif(1,min=0.4, max=0.6) X <- z1 Y = cor*z1+(1-cor)*z2 mat1 <- cbind(X,Y) dev1 <- sample(-40:40, 1, replace=T) cut1 <- mean(X) + dev1 dev2 <- sample(12:54, 1, replace=T) cut2 <- mean(X) + dev1 + dev2 X2 <- X-cut1 Y2 <- Y-cut2 c3 <- cor(X2,Y2) mat2 <-cbind(X2,Y2) a11 <- ifelse( X < cut1 & Y < cut2, 1, 0) a12 <- ifelse( X < cut1 & Y >= cut2, 1, 0) a21 <- ifelse( X >= cut1 & Y < cut2, 1, 0) a22 <- ifelse( X &...
2011 Oct 11
1
warning with cut2 function
Dear r user, please find my attached sample of the dataset i? am using to create a crosstable and eventually plot a histogram from the output. I am using? the cut2 function to create bins, about 7 of them using the code after reading the data: cluster <- cut2(cross_val$value, g=7) I get the warning: Warning message: In min(xx[xx > upper]) : no non-missing arguments to min; returning Inf additionally, the bins become 6 instead of 7 through the crossT...
2012 Oct 17
2
cut2 error
To R users, I am trying to use cut2 function from the 'Hmisc' library. However, when I try and run the function on the following variable, I get an error message (displayed below). I suspect it is because of the NA but I have no idea how to address the error. Many thanks to any insights. structure(list(var1 = c(97, 97, 98...
2009 Oct 23
1
cut2 once, bin twice...
Hello, I'm using the Hmisc cut2 function to bin a set of data. It produces bins that I like with results like this: [96,270]:171 [69, 96): 54 [49, 69): 40 [35, 49): 28 [28, 35): 14 [24, 28): 8 (Other) : 48 I would like to take a second set of data, and assign it to bins based on factors defined by my call to cut 2. Does anyo...
2010 Mar 08
1
Help with Hmisc, cut2, split and quantile
...p://n4.nabble.com/file/n1584647/Sample_table.txt Sample_table.txt is attached but the data looks like this: Actual Target -0.125 0.016124906 0.135 0.120799865 ... ... ... ... I want to be able to break the data into tables based on quantiles in the "Target" column. I can see (using cut2, and also quantile) how to get the barrier points between the different quantiles, and I can see how I would achieve this if I was just looking to split up a vector. However I am trying to break up the whole table based on those quantiles, not just the vector. The following code shows me the rang...
2012 Oct 17
2
loop of quartile groups
Greetings R users, My goal is to generate quartile groups of each variable in my data set. I would like each experiment to have its designated group added as a subsequent column. I can accomplish this individually with the following code: brks <- with(data_variables, cut2(var2, g=4)) #I don't want the actual numbers, I need a numbered group data$test1=factor(brks, labels=1:4) However, I cannot get a loop to work nor can I get a loop to add the columns with an appropriate name (ex. quartile_variable). I have tried multiple different ways but can't seem t...
2004 Jul 06
3
Improving effeciency - better table()?
...I've been running some simulations for a while and the performance of R has been great. However, I've recently changed the code to perform a sort of chi-square goodness-of-fit test. To get the observed values for each cell I've been using table() - specifically I've been using cut2 from Hmisc to divide up the range into a specified number of cells and then using table to count how many observations appear in each cell. > obs <- table(cut2(z.trun, cuts=breaks)) Having done this I've found that the code takes much longer to run - up to 10x as long. Is there a...
2009 May 20
1
sem with categorical data
...socserv.mcmaster.ca/jfox/Misc/sem/SEM-paper.pdf. When I apply the hetcor function, I receive the following error: Error in checkmvArgs(lower = lower, upper = upper, mean = mean, corr = corr, : at least one element of 'lower' is larger than 'upper' Example: set.seed(781) q1 <- cut2(x = rlnorm(n = 1e2, m = 2), cuts = seq(1,6)) q2 <- cut2(x = rlnorm(n = 1e2, m = 0), cuts = seq(1,6)) q3 <- cut2(x = rlnorm(n = 1e2, m = 1), cuts = seq(1,6)) dat <- data.frame(q1,q2,q3) hetcor(data = dat, ML = T, pd = T, use = 'p') Any help in understanding and correcting the error...
2008 Sep 19
0
Error message in lmer
...uot;, so the solutions that were offered did not solve my problem (family="quasipoisson") (e.g. adding control=list(usePQL=FALSE,msVerbose=TRUE) does not make sense nor changes anything - error remains). A sample data (d.rba) set is pasted at the end. attach (d.rba) y <- d.rba$ms cut2 <- d.rba$cut^2 boot <- 10 index <- seq(1, length(y), 1) cut.pred <- seq(0,20,2) cut2.pred<-cut.pred^2 pred <- matrix(data = NA, nrow=boot, ncol=length(cut.pred)) for (j in 1 : boot){ id <- sample(index, replace=T) y.boot <- y[id] age_insects.boot <- age_insects[id] c...
2008 Oct 20
4
aggregating along bins and bin-quantiles
Dear all, I would like to aggregate a data frame (consisting of 2 columns - one for the bins, say factors, and one for the values) along bins and quantiles within the bins. I have tried aggregate(data.frame$values, list(bin = data.frame $bin,Quantile=cut2(data.frame$bin,g=10)),sum) but then the quantiles apply to the population as a whole and not the individual bins. Upon this realisation I have tried aggregate(data.frame$values, list(bin = data.frame $bin,Quantile=tapply(data.frame$values,data.frame$bin,cut2,g=10)),sum) which gives the follow...
2009 Sep 22
1
cut and re-factor data
...data for each age group. I only have this summary information in R at the moment. I want to create a new factor that aggregates the age factors if the existing factors have insufficient counts. Then I can use aggregate to build a new data set. I figured out I can get the cut values I want using cut2 from Hmisc >count [1] 10 20 20 50 50 50 50 50 50 50 50 50 50 50 10 20 20 >age_bucket <- seq (0,80,5) >age_f <- factor(age_bucket) > age_f [1] 0 10 15 20 25 30 35 40 45 5 50 55 60 65 70 75 80 Levels: 0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 ct <- rep(age_bucket, co...
2007 Dec 13
3
what does cut(data, breaks=n) actually do?
Hello, I'm trying to bin a quantity into 2-3 bins for calculating entropy and mutual information. One of the approaches I'm exploring is the cut() function, which is what the mutualInfo function in binDist uses. When it's called in the format cut(data, breaks=n), it somehow splits the data into n distinct bins. Can anyone tell me how cut() decides where to cut? Thanks, Melissa
2010 Aug 06
1
Grouping clusters from dendrograms
...seems to be producing odd results whereby it is grouping data that overlap branches. However, I'm not sure if this is because of the script I am using to visualise the data which may be incorrect. The script I tried was: > dendro<-hclust(as.dist(combo2),method="average") > cut2<-cutreeDynamicTree(dendro,maxTreeHeight=1,deepSplit=TRUE,minModuleSize=1) I then used the following to visualise the data: > cut2colour<-labels2colors(cut2) > plotDendroAndColors(dendro,cut2colour,"Dynamic Tree Cut", > dendroLabels=FALSE,hang=0.03,addGuide=TRUE,guideHang=...
2012 Feb 22
2
rank with uniform count for each rank
Hello, What is the best way to get ranks for a vector of values, limit the range of rank values and create equal count in each group? I call this uniform ranking...uniform count/number in each group. Here is an example using three groups: Say I have values: x = c(3, 2, -3, 1, 0, 5, 10, 30, -1, 4) names(x) = letters[1:10] > x a b c d e f g h i j 3 2 -3 1 0 5 10 30 -1 4 I
2009 Feb 02
1
survfit using quantiles to group age
I am using the package Design for survival analysis. I want to plot a simple Kaplan-Meier fit of survival vs. age, with age grouped as quantiles. I can do this: survplot(survfit(Surv(time,status) ~ cut(age,3), data=veteran) but I would like to do something like this: survplot(survfit(Surv(time,status) ~ quantile(age,3), data=veteran) #will not work ideally I would like to superimpose
2009 Sep 30
1
rcs fits in design package
Hi all, I have a vector of proportions (post_op_prw) such that >summary(amb$post_op_prw) Min. 1st Qu. Median Mean 3rd Qu. Max. NA's 0.0000 0.0000 0.0000 0.3985 0.9134 0.9962 1.0000 > summary(cut2(amb$post_op_prw,0.0001)) [0.0000,0.0001) [0.0001,0.9962] NA's 1904 1672 1 I want to use post_op_prw as a predictor variable in an OLS model. I decided to fit it using a restricted cubic spline. But, I'm seeing...
2005 Feb 05
0
Rép : 2 small problems: integer division and the nature of NA
...u also for the explanations of rounding errors with floating point arithmetics. I did not expect it. This small error was a real problem for me as I was trying to find a way to recode numeric values into intervals. Because I wanted to retain numeric values as a result, I tried not to use cut or cut2. Hence to convert a range of temperatures into 0.2 degree intervals I had written: (lets first make a fake temperature variable k for testing) k <- seq(-5,5,0.1) k1 <- ifelse(k<0,-0.2*(abs(k) %/% 0.2) - 0.1, 0.2 *(k %/% 0.2) + 0.1) Note that this works well to quickly recode a numeric v...
2008 Apr 17
1
Error in Design package: dataset not found for options(datadist)
Hi, Design isn't strictly an R base package, but maybe someone can explain the following. When lrm is called within a function, it can't find the dataset dd: > library(Design) > age <- rnorm(30, 50, 10) > cholesterol <- rnorm(30, 200, 25) > ch <- cut2(cholesterol, g=5, levels.mean=TRUE) > fit <- function(ch, age) + { + d <- data.frame(ch, age) + dd <- datadist(d) + options(datadist="dd") + lrm(ch ~ age, data=d, x=TRUE, y=TRUE) + } > fit(ch, age) Error in Design(eval(m, sys.parent())) : dataset dd not fou...
2007 Nov 24
1
Hmisc: can not reproduce figure 4 of Statistical Tables and Plots using S and LATEX
Dear R-users: I can not reproduce figure 4 of *Statistical Tables and Plots using S and LATEX* by Prof. Frank Harrell with the following code: rm(list=ls()) library(Hmisc) getHdata(pbc) attach(pbc) age.groups <- cut2(age, c(45,60)) g <- function(y) apply(y, 2, quantile, c(.25,.5,.75)) y <- with(pbc, cbind(Chol=chol,Bili=bili)) # You can give new column names that are not legal S names # by enclosing them in quotes, e.g. 'Chol (mg/dl)'=chol vars <- with(pbc, c(label(chol), label(bili))) label(y)...
2001 Oct 02
4
plot of Bernoulli data
I have some Bernoulli data something like this: x<-sort(runif(100,1,20)) p<-pnorm(x,10,3) y<-as.numeric(runif(x)<p) plot(x,y) lines(x,p) This plot is not very satisfactory because the ogive does not visually fit the (0,1) points very well, and also because the points tend to fall on top of one another. The second problem can be eliminated by adding vertical jitter. However I was