[R] can I calculate density for only non-negative value?

2013-08-19 Thread Gallon Li
x=rchisq(100,1) density(x) the density plot will give density for negative part also. of course I can truncate the plot to only view the non-negative part. I wonder if there is a program to compute density for a user-specified range, in this case, only [0, infinity). [[alternative HTML

[R] calculate time from dates

2013-07-11 Thread Gallon Li
My data are from 2008 to 2010, with repeated measures for same subjects. I wish to compute number of months since january 2008. The data are like the following: ID date 1 4/12/2008 1 4/13/2008 1 5/11/2008 2 3/21/2009 2 4/22/2009 2 8/05/2009 ... the date column are in the format %m/%d/%y. i wish

[R] how to choose dates data?

2013-07-04 Thread Gallon Li
i have converted my data into date format like below: day=as.Date(originaldate,%m/%d/%Y) day[1:5] [1] 2008-04-12 2011-07-02 2011-09-02 2008-04-12 2008-04-12 I wish to select only those observations from 2007 to 2009, how can I select from this list? [[alternative HTML version

[R] find the position of first observation for each subject

2013-06-13 Thread Gallon Li
suppose I have the following data id=c(rep(1,3),rep(2,5),rep(3,4)) time=c(seq(1,3),seq(2,6),seq(1,4)) ds=cbind(id,time) ds id time [1,] 11 [2,] 12 [3,] 13 [4,] 22 [5,] 23 [6,] 24 [7,] 25 [8,] 26 [9,] 31 [10,] 32 [11,] 33

[R] change factor to mtrix

2013-06-12 Thread Gallon Li
i wish to change a column of factor variable to multiple columns of zero-ones for example, my factor could be ff=c('a','a','b','b','c','c') then I want to have two columns (for three levels) that are 0 0 0 0 1 0 1 0 0 1 0 1 how can i do this fast? [[alternative HTML version deleted]]

[R] how to fit Cox model with time dependent covariates?

2012-10-16 Thread gallon li
I wonder if there is a simple way of doing this? My data is very simple, a right censored outcome (T,delta) and the predictor is simply Z*t, i.e., the cox model is like h(t)=h0(t)exp(beta*Z*t) can this be done with coxph? __ R-help@r-project.org

[R] define variables from a matrix

2011-08-12 Thread gallon li
I have a following matrix and wish to define a variable based the variable A=matrix(0,5,5) A[1,]=c(30,20,100,120,90) A[2,]=c(40,30,20,50,100) A[3,]=c(50,50,40,30,30) A[4,]=c(30,20,40,50,50) A[5,]=c(30,50,NA,NA,100) A [,1] [,2] [,3] [,4] [,5] [1,] 30 20 100 120 90 [2,] 40 30

[R] define variables from rows of a matrix

2011-08-10 Thread gallon li
I have a following matrix and wish to define a variable based the variable A=matrix(0,5,5) A[1,]=c(30,20,100,120,90) A[2,]=c(40,30,20,50,100) A[3,]=c(50,50,40,30,30) A[4,]=c(30,20,40,50,50) A[5,]=c(30,50,NA,NA,100) A [,1] [,2] [,3] [,4] [,5] [1,] 30 20 100 120 90 [2,] 40 30

[R] select from matrix

2011-08-07 Thread gallon li
Suppose I have a matrix like A=matrix(0,4,6) A[1,]=c(16,10,2,4,8,7) A[2,]=c(16,10,12,14,8,7) A[3,]=c(16,10,13,15,19,17) A[4,]=c(16,9,13,15,9,7) A [,1] [,2] [,3] [,4] [,5] [,6] [1,] 16 102487 [2,] 16 10 12 1487 [3,] 16 10 13 151917 [4,]

[R] select element from each row of the matrix

2011-07-20 Thread gallon li
I have a 5 column matrix like 12 10 8 6 3 10 9 8 7 5 14 NA 4 NA NA NA 15 NA 10 NA 5 ... I want to select the position of the first entry for each row =5 for example, for the first row, I want to select the last element and return its position as 5; for th e third row, I want to select the third

[R] how to select the first observation only?

2010-04-21 Thread gallon li
Dear r-helpers, I have a very simple question. Suppose my data is like id=c(rep(1,2),rep(2,2)) b=c(2,3,4,5) m=cbind(id,b) m id b [1,] 1 2 [2,] 1 3 [3,] 2 4 [4,] 2 5 I wish to select the first observation for each id. That is, I want to quickly select two rows: id b 1 2 2 4 only. how

[R] how to select the last non-'NA' observation in a row

2010-04-20 Thread gallon li
I have a matrix of the following form: time id0 2 4 6 9 12 14 3 9 8 NA NA NA NA NA 7 3 NA 3 NA 3 NA 4 13 11 6 7 NA 5 NA 6 . I hope for each row to select the last observation which is not 'NA'. For example, for the first row, id=3, the value I want to select

[R] select observations from longitudinal data

2009-03-29 Thread gallon li
Suppose I have a long format for a longitudinal data id time x 1 1 10 1 2 11 1 3 23 1 4 23 2 2 12 2 3 13 2 4 14 3 1 11 3 3 15 3 4 18 3 5 21 4 2 22 4 3 27 4 6 29 I want to select the x values for each ID when time is equal to 3. When that observation is not observed, then I want to replace it

[R] select observations from longitudinal data set

2009-01-17 Thread gallon li
I have the following longitudinal data: id time y 1 1 10 1 2 12 1 3 15 1 6 18 2 1 8 2 3 9 2 4 11 2 5 12 3 1 8 3 4 16 4 1 9 4 5 13 5 1 7 5 2 9 5 6 11 I want to select the observations at time 4. if the observation at time 4 is missing, then i want to slect the observation at time 3. if the

[R] the first and last observation for each subject

2009-01-02 Thread gallon li
I have the following data ID x y time 1 10 20 0 1 10 30 1 1 10 40 2 2 12 23 0 2 12 25 1 2 12 28 2 2 12 38 3 3 5 10 0 3 5 15 2 . x is time invariant, ID is the subject id number, y is changing over time. I want to find out the difference between the first and last observed y value for each

[R] select a subset

2008-11-24 Thread gallon li
I have the complete data like id time censor 1 10 0 1 20 0 1 30 0 2 10 0 2 20 1 2 30 0 2 40 0 3 10 0 3 20 0 3 30 1 for id 1, i want to select the last row since all censor indicator is 0; for id 2, i want to select the row where censor ==1; for id 3, i also want to select the row where

[R] Fwd: select a subset

2008-11-24 Thread gallon li
-- Forwarded message -- From: gallon li [EMAIL PROTECTED] Date: Tue, Nov 25, 2008 at 1:58 PM Subject: Re: [R] select a subset To: Stefan Grosse [EMAIL PROTECTED] I am sorry but my question is not solvable by using subset alone. You see, the selection criterion is different

[R] count the cumulative for each subject

2008-11-23 Thread gallon li
I have a data set like the following: subject visit x1 1 1 0.5 1 2 1.2 1 3 0.7 2 1 0.4 2 2 0.6 2 3 1.0 . where x1 is the interval between the two visits. Now I want to calculate the cumulative intervals since the beinging, for example subject visit x1 cum 1 1 0.5 0.5 1 2 1.2 0.5+1.2 1 3

[R] count zero or one in a list

2008-10-24 Thread gallon li
I have a list of {0,1} values, say y-c(0,0,0,1,1,0,0,1,0,1,1,1,1) I want to compute the first few zeros and the last few ones. So the output I expect is 3 and 4 for this vector. Is there a fast way to match the numbers easily? [[alternative HTML version deleted]]

[R] print results from R

2008-10-08 Thread gallon li
I want to print the following multiple boxes of output from R. - 1st stage |2nd stage | 3rd stage | x1|x2 | x3| | |

[R] ROC curve from logistic regression

2008-09-08 Thread gallon li
I know how to compute the ROC curve and the empirical AUC from the logistic regression after fitting the model. But here is my question, how can I compute the standard error for the AUC estimator resulting form logistic regression? The variance should be more complicated than AUC based on known

Re: [R] can we include nonparametric component for survival regression?

2008-02-19 Thread gallon li
I've figured it out by repeatedly testing. It is to use a type='term' statement, just as used in gam. sorry to bother. On 2/19/08, gallon li [EMAIL PROTECTED] wrote: Thanks a lot, Prof Lumley. Now I can fit a model like coxfit=coxpy((time,censor)~pspline(x1)+x2+x3) but I am not sure how

Re: [R] can we include nonparametric component for survival regression?

2008-02-19 Thread gallon li
, then the example in help manule can be used as plot(x1, predict(coxfit)) but with more than 1 predictor, i am not sure how to select the one i want. On 2/19/08, Thomas Lumley [EMAIL PROTECTED] wrote: On Mon, 18 Feb 2008, gallon li wrote: i am trying to fit a survival regression model (cox model

[R] can we include nonparametric component for survival regression?

2008-02-18 Thread gallon li
i am trying to fit a survival regression model (cox model or parametric model) in R by including the covariate effects as a function m(x) instead of just beta*x. is it possible to fit such a model? can someone recommend some reference? I searched but only found a package called addreg where the

[R] KM estimation for interval censoring?

2008-01-27 Thread gallon li
Does anybody know if there is such a function to estimate the distribution for interval censored data? survfit doesn't work for this type of data as I tried various references. [[alternative HTML version deleted]] __ R-help@r-project.org

[R] want to make a plot similar to ecdf

2007-12-19 Thread gallon li
I have a sample of observations: yy [1] 0. 2.3972 4.3500 -4.1972 0.6361 [6] 1.0806 5.9056 -1.8722 2.1333 -1.1806 [11] 3.6167 0.8778 8.3389 3.8417 1. [16] -3.7611 -11.6778 -2.0306

[R] plot cummulative sum from calendar time

2007-12-18 Thread gallon li
I have the following list of observations of calendar time: [1] 03-Nov-1997 09-Oct-1991 27-Aug-1992 01-Jul-1994 19-Jan-1990 12-Nov-1993 [7] 08-Oct-1993 10-Nov-1982 08-Dec-1986 23-Dec-1987 02-Aug-1995 20-Oct-1998 [13] 29-Apr-1991 16-Mar-1994 20-May-1991 28-Dec-1987 14-Jul-1999 27-Nov-1998 [19]

[R] how to compute highest density interval?

2007-11-24 Thread gallon li
Suppose i want to compute a 95% highest density for a beta distribution beta(a,b) the two end points x1 and x2 shoudl satisfy the following two equations: pbeta(x1,a,b)-pbeta(x2,a,b)=95% dbeta(x1,a,b)=dbeta(x2,a,b) Is there any fast way to compute x1 and x2 in R? [[alternative HTML

[R] is there a similar function to perform repeated statements as in SAS PROC MIXED?

2007-10-24 Thread gallon li
PROC MIXED is used to fit mixed effects model for correlated data. Usually we can use either a REPEATED statment or a RANDOM statement. The random statement is corresponding to lme function in R -- specifying a random effect term. The repeated statement actually directly specifies the