Re: [R] Ctree plot

2012-08-09 Thread Weidong Gu
Hi, You may want to check grid.arrange in gridExtra package. Weidong On Thu, Aug 9, 2012 at 7:36 AM, rodrock wrote: > HI everybody! > > Has anybody figure out how would be possible to plot several ctree plots > beside each other? > I would really appreciate it > My idea would be like this, but

Re: [R] HELP

2012-07-26 Thread Weidong Gu
Hi, You can try predict.rpart in rpart package for prediction on a test data. ?predict.rpart Weidong On Thu, Jul 26, 2012 at 12:30 PM, Orla Carey wrote: > Hello, > > I am running classification trees fro the purpose of predicting dividends. > I have training and test data sets, but am running t

Re: [R] Reorder in decreasing order

2012-07-22 Thread Weidong Gu
Sverre, have you tried to put minus(-) in front of the variable by which you order the other? weidong On Sun, Jul 22, 2012 at 12:27 PM, Sverre Stausland wrote: > reorder() is probably the best way to order the levels in a vector > without manually specifying the order. But reorder() orders by d

Re: [R] significance test interquartile ranges

2012-07-13 Thread Weidong Gu
Sorry, I meant Kolmogorov-Smirnov test. Thanks Peter for correction. Weidong On Fri, Jul 13, 2012 at 4:56 PM, Peter Ehlers wrote: > On 2012-07-13 13:33, Weidong Gu wrote: >> >> Hi Joerg, >> >> Seems Mann-Whitney-Wilcoxon test (ks.test in R) would do the work >>

Re: [R] significance test interquartile ranges

2012-07-13 Thread Weidong Gu
Hi Joerg, Seems Mann-Whitney-Wilcoxon test (ks.test in R) would do the work which tests differences anywhere in two distributions, e.g. tails, interquartiles and center. Weidong Gu On Fri, Jul 13, 2012 at 7:32 AM, Schaber, Jörg wrote: > Hi, > > I have two non-normal distribution

Re: [R] strang behaviour of mice package

2012-06-17 Thread Weidong Gu
Hi, In my case, that was due to the existence of highly correlated variables. see loggedEvents in the help file of mice. Weidong Gu On Sat, Jun 16, 2012 at 3:33 PM, b04877054 wrote: > I have the same problem. How did you end up solving yours? > > -- > View this message in context:

Re: [R] Grouping and/or splitting

2012-04-03 Thread Weidong Gu
how about split(inpfil, paste(inpfil[,1],inpfil[,2],sep=',')) Weidong Gu On Tue, Apr 3, 2012 at 6:42 PM, Ashish Agarwal wrote: > I have a dataframe imported from csv file below: > > Houseid,Personid,Tripid,taz > 1,1,1,4 > 1,1,2,7 > 2,1,1,96 > 2,1,2,4 > 2,1,

Re: [R] list assignment syntax?

2012-03-30 Thread Weidong Gu
You don't need temporary variable x c<-f(1,2)[[1]] d<-f(1,2)[[2]] Weidong Gu On Fri, Mar 30, 2012 at 6:40 PM, ivo welch wrote: > Dear R wizards:  is there a clean way to assign to elements in a list? >  what I would like to do, in pseudo R+perl notation is > >  f <-

Re: [R] lasso constraint

2012-03-27 Thread Weidong Gu
values. cross validation is used to estimate the value of the turning parameter which gives the smallest errors (mse or deviance) on testing data. Weidong Gu On Tue, Mar 27, 2012 at 10:35 AM, yx78 wrote: > In the package lasso2, there is a Prostate Data. To find coefficients in the > prostate

Re: [R] NA in R package randomForest

2012-03-26 Thread Weidong Gu
Your data set probably has character variables. You can transform them into factors before running na.roughfix. Weidong Gu On Mon, Mar 26, 2012 at 8:17 AM, silje skår wrote: > I have a question regarding NA in randomForest (in R). I have a dataset > which include both numerical a

Re: [R] string substitution for argument in function

2012-03-25 Thread Weidong Gu
Hi, This may help a = c('one','two','three') data.frame(eval(substitute(rbind(var,2),list(var=a)))) ?substitute ?eval Weidong Gu On Sun, Mar 25, 2012 at 5:22 PM, Pedro Martinez wrote: > hello, > I want to iterate through a list of names and use each el

Re: [R] Order of terms in formula changes aov() results

2012-03-23 Thread Weidong Gu
is the method by aov) is a sequential method. Therefore, order of variables in the model matters. For your situation, you may want to use type II or type III SS (check Anova in car) because they are estimates adjusted for other variables in the model, thus order-independent. Weidong Gu On Thu, Mar

Re: [R] glmnet: obtain predictions using predict and also by extracting coefficients

2012-03-21 Thread Weidong Gu
(data.test). It's not surprise the predictions are different. Weidong Gu On Wed, Mar 21, 2012 at 2:35 PM, Juliet Hannah wrote: > All, > > For my understanding, I wanted to see if I can get glmnet predictions > using both the predict function and also by multiplying coefficients

Re: [R] How to deal with missing values when using Random Forrest

2012-02-26 Thread Weidong Gu
Hi, You can set na.action=na.roughfix which fills NAs with the mean or mode of the missing variable. Other option is to impute missing values using rfImpute, then run randomForest on the complete data set. Weidong Gu On Sat, Feb 25, 2012 at 6:24 PM, kevin123 wrote: > I am using the pack

Re: [R] stepwise selection for conditional logistic regression

2012-02-17 Thread Weidong Gu
stepAIC works for an object of clogit. Weidong Gu On Fri, Feb 17, 2012 at 2:10 AM, Subha P. T. wrote: > > >  Hi, > > Is there any function available to do stepwise selection of variables in > Conditional(matched) logistic regression( clogit)? step, stepwise  etc are &g

Re: [R] Lattice - different axis length

2012-02-07 Thread Weidong Gu
Hi, set scales=list(x=list(relation='free')) may help. Weidong Gu On Tue, Feb 7, 2012 at 6:42 AM, Florian Weiler wrote: > Dear all, > > I have a question about the lattice package, more specifically about the > control of the x-axis length in the different panels. I use t

Re: [R] plotting regression line in with lattice

2012-01-13 Thread Weidong Gu
Hi, Since trt is a factor, you use it for indexing. try just delete in the code fill <- my.fill[combined$trt[subscripts]] Weidong Gu On Fri, Jan 13, 2012 at 11:30 AM, matteo dossena wrote: > #Dear All, > #I'm having a bit of a trouble here, please help me... > #I have this

Re: [R] glm predict issue

2011-12-26 Thread Weidong Gu
Hi, This might be due to the fact that factor levels are arbitary unless they are ordinal, even that quantitative relationships between levels are unclear. Therefore, the model has no way to predict unseen factor levels. Does it make sense to treat 'No_databases' as numeric instead of a factor va

Re: [R] How to compute 95%CI for OR from logistic regression?

2011-12-13 Thread Weidong Gu
One simple option is to use confint function exp(confint(result)) Weidong On Tue, Dec 13, 2011 at 7:16 AM, 孟欣 wrote: > Hi all: > My data has 3 variables: > age(3levels : <30y=1  30-50y=2, >50y=3) > gender(Male=0, Female=1) > CD4 cell count(raw lab measurement) > y(1:death  0:alive) > > I perfor

Re: [R] Imputing data

2011-12-02 Thread Weidong Gu
Hi, For imputation using randomForest package, check ?rfImpute Weidong On Fri, Dec 2, 2011 at 6:00 PM, Peter Langfelder wrote: > On Fri, Dec 2, 2011 at 2:16 PM, khlam wrote: >> So I have a very big matrix of about 900 by 400 and there are a couple of NA >> in the list. I have used the followi

Re: [R] Question about randomForest

2011-11-27 Thread Weidong Gu
urn an > identical result to that used to generate the error rate for the final > tree constructed?? > > Sorry that is a bit long winded, but I hope someone can point out > where I'm going wrong and set me straight. > > Thanks! > > On Sun, Nov 27, 2011 at 11:44 AM, Wei

Re: [R] Question about randomForest

2011-11-26 Thread Weidong Gu
Hi Matthew, The error rate reported by randomForest is the prediction error based on out-of-bag OOB data. Therefore, it is different from prediction error on the original data since each tree was built using bootstrap samples (about 70% of the original data), and the error rate of OOB is likely h

Re: [R] computationally singular error with mice()

2011-11-26 Thread Weidong Gu
Hi Fei, I wouldn't worry to much about categorical variables for mice. Mice would use logisitic regression for binary and polytomous logistic regression for categorical variables with >2 levels. However, you should not include factors with a lot of levels, saying>30, in imputation models because i

Re: [R] How to explain interaction variable in Linear regression?

2011-11-23 Thread Weidong Gu
Hi, The significant interaction between A (continous) and B (categorical) means that the slopes of Y in relation to A are different for classes of B. Since your categorical B was binary, the default reference class (B2) was intecept, and the slope of A for (B2) was 0.0017799. However, the slope of

Re: [R] help with formula for clogit

2011-11-07 Thread Weidong Gu
clogit needs to spell out formula plus strata, you can try modify the code ... d2=d[,c(mols,'group','Age','strata')] fo<-as.formula(paste(paste('group~','Age',sep=''),'strata(strata)',sep='+')) log.reg<-clogit(fo,data=d2) ... Weidong On Mon, Nov 7, 2011 at 10:19 AM, 1Rnwb wrote: > I would like t

Re: [R] Sampling with conditions

2011-11-07 Thread Weidong Gu
Not sure this is valid that you can have 9 random samples out of 10, but the last one has to be fixed to meet the restraint, sum=10. Weidong On Mon, Nov 7, 2011 at 5:22 PM, SarahJoyes wrote: > Hey everyone, > I am at best, an amateur user of R, but I am stuck on how to set-up the > following sit

Re: [R] oversampling code

2011-10-31 Thread Weidong Gu
You should figure out how many samples you want for Y=1 and 0, then sample from the relevant subset dfrm[dfrm$Y==1] by sampling row.names(dfrm[dfrm$Y==1] using replace=FALSE ?sample On Mon, Oct 31, 2011 at 8:18 PM, Comcast wrote: > > > On Oct 31, 2011, at 1:54 PM, loubna ibn majdoub hassani > w

Re: [R] oversampling code

2011-10-31 Thread Weidong Gu
For a data set dat with variable 'case', it follows sam.rate=0.9 n.ctrl<-nrow(dat[dat$case==0,]) sam.ctrl<-dat[sample(row.names(dat[dat$case==0],n.ctrl*sam.rate,replace=F),] rbind(dat[dat$case==1,],sam.ctrl) Weidong Gu On Mon, Oct 31, 2011 at 1:54 PM, loubna ibn majdoub hassani

Re: [R] help to extract data with R

2011-10-30 Thread Weidong Gu
One option is to use table to get the number of repeats tab<-table(tr1$time)==3 time3<-names(tab)[tab] tr1[tr1$time%in%time3,] Weidong Gu On Sun, Oct 30, 2011 at 5:10 PM, Zheng Lu wrote: > > > > > With the following dataset, trl =1, 2,3, how to extract data with the tim

Re: [R] GLM Help

2011-10-28 Thread Weidong Gu
(xf), family = poisson, data = dat) Coefficients: (Intercept) as.numeric(xf) 1.59047 -0.02673 Weidong Gu On Fri, Oct 28, 2011 at 4:21 PM, CES wrote: > Hey all, > >  I am attempting to replicate my results achieved in another program within > R (so I can expand my op

Re: [R] FOR loop with statistical analysis for microarray data

2011-10-27 Thread Weidong Gu
; > and the "fc" values are repeated over until the end of the rows and > the "pv" is the same all across the samples...how can i fix it?! > > ...i apologize if it's a silly situation but i'm new to this and can't > get my head around it! > >

Re: [R] FOR loop with statistical analysis for microarray data

2011-10-27 Thread Weidong Gu
ate it!! > > Sent from my -DROID- > > On Oct 26, 2011 6:56 PM, "Weidong Gu"  wrote: >> >> If you provide an example data (y1 and y2 in the loop), you might have >> got specific helps already. A few things in your loop seem suspicious. >> fc and pv are vecto

Re: [R] FOR loop with statistical analysis for microarray data

2011-10-26 Thread Weidong Gu
If you provide an example data (y1 and y2 in the loop), you might have got specific helps already. A few things in your loop seem suspicious. fc and pv are vectors, and in each loop you redesigned the whole vectors and specific indices twice. That may cause your problems. Weidong Gu On Wed

Re: [R] Logistic Regression - Variable Selection Methods With Prediction

2011-10-26 Thread Weidong Gu
Check glmulti package for all subset selection. Weidong Gu On Wed, Oct 26, 2011 at 12:35 PM, RAJ wrote: > Can I atleast get help with what pacakge to use for logistic > regression with all possible models and do prediction. I know i can > use regsubsets but i am not sure if i

Re: [R] Adding rows to a table with a loop

2011-10-24 Thread Weidong Gu
package which conducts model selection out of all potential combinations, even including interactions if you don't have many variables. HTH Weidong Gu On Mon, Oct 24, 2011 at 11:58 AM, MJS wrote: > Hi All, > Its a bit of a beginners question I'm afraid. > I have a looped stepwis

Re: [R] Expanding rows of a data frame into multiple rows

2011-10-22 Thread Weidong Gu
This may work obs.l<-sapply(input$observations,length) desire.output<-data.frame(site=rep(1:6,obs.l),obs=unlist(input$observations)) Weidong Gu On Sat, Oct 22, 2011 at 7:51 PM, Peter Meilstrup wrote: > The setup: I have a data frame where one column is in list mode, and > each en

Re: [R] question about aggregate

2011-10-22 Thread Weidong Gu
91.4119070 > 27 0.4   S  81.9875960 > 28 0.6   S  11.3183831 > 29 0.8   S   1.8843307 > 30 1.0   S   0.9310779 > > for exemple, for the last line, I want aggregate to show me the number of > lines with col1=1 and col2=S in stead of the mean

Re: [R] question about aggregate

2011-10-22 Thread Weidong Gu
Is this waht you want? sci[,5][sci[,2]==0 & sci[,1]==L] Weidong On Sat, Oct 22, 2011 at 8:19 AM, Adel ESSAFI wrote: > Hi, > It is not what I want, but, thx anyway. > Regards > > > 2011/10/22 Weidong Gu >> >> try this >> >> table(sci[,2]=0,sci[,1]=

Re: [R] question about aggregate

2011-10-22 Thread Weidong Gu
try this table(sci[,2]=0,sci[,1]=L) Weidong Gu On Sat, Oct 22, 2011 at 7:51 AM, Adel ESSAFI wrote: > Hello, > is there any help please. > Regards > > > 2011/10/21 Adel ESSAFI > >> Hello >> I am discovering R and I find it is really very powerful. >> >

Re: [R] Working With Variables Having Different Lengths

2011-10-21 Thread Weidong Gu
imputations are based on some strong and untestable assumptions. Weidong Gu On Fri, Oct 21, 2011 at 12:13 PM, Rich Shepard wrote: >  Because of regulatory requirement changes over several decades and weather > conditions preventing site access the variables in my data set have > differen

Re: [R] identifying groups in xyplot

2011-10-20 Thread Weidong Gu
Hi, Just include pch=c(1,2,3), col=c('red','blue','yellow') or your choices in xyplot Weidong Gu On Thu, Oct 20, 2011 at 2:15 PM, wisc_maier wrote: > There have been posts in the past regarding similar questions, but many of > them looked dated. I am using

Re: [R] getting basic descriptive stats off multiple imputation data

2011-10-18 Thread Weidong Gu
Mike, You can retrieve each of imputed data sets and use Rubin's rule for combined analysis. I am not sure how to do combined analysis of cov, but mean and SE would be estimiable. For mi package to get individual copies of imputed data ?mi.completed HTH Weidong Gu On Tue, Oct 18, 2011

Re: [R] How to plot CI's (llim ulim) on ecodist mgram

2011-10-16 Thread Weidong Gu
It is good to provide the code but please make sure it is reproducible? e.g. XZ is not defined in mgram(XY,XZ)? Weidong Gu On Sun, Oct 16, 2011 at 7:10 PM, Nevil Amos wrote: > I would like to put confidence intervals on a mantel corellogram > they are already calculated in the pmgram obje

Re: [R] question: ragged array

2011-10-16 Thread Weidong Gu
if you set parameter simplify=TRUE, it returns a vector of the ragged mean. In your case, mean_rating <- tapply(ratok$value, ratok$project_id , mean,simplify = TRUE) df<-data.frame(ID=dimnames(mean_rating)[[1]], mean=mean_rating) Weidong Gu On Sun, Oct 16, 2011 at 9:53 AM, Helene Sc

Re: [R] grouped lattice plot with overall regression line

2011-10-16 Thread Weidong Gu
If you want to draw the global regression line in each panel, you can try xyplot(T~A|speaker,data=spk0,layout=c(4,5),type='p',groups=fns), panel=function(x,y,...){ panel.xyplot(x,y,...) panel.abline(lm(y~x,data=spk0))}) Weidong Gu 2011/10/16 조혜선 : > I'd like to draw a lattic

Re: [R] non-parametric permutation and signed paired-difference distributions

2011-10-14 Thread Weidong Gu
On Fri, Oct 14, 2011 at 11:38 AM, Michael Friendly wrote: > Hi all > Consider the classic data below from Darwin on the heights of 15 pairs of > zea mays (corn) plants > either cross-fertilized or self-fertilized, where the goal is to see if it > makes a difference. > >> head(ZeaMays) >  pair pot

Re: [R] change uppercase variables

2011-10-14 Thread Weidong Gu
?tolower Weidong Gu On Fri, Oct 14, 2011 at 12:12 PM, Jose Bustos Melo wrote: > > >  Hello everyone, > > I'm trying to change the name variables of a big dataset. Here's more than > 300 variables. The point is that I have to match it with another dataset that &

Re: [R] Split a list

2011-10-14 Thread Weidong Gu
It would be nice if you could provide a sample. However, if the data in the list have the same colnames, you can combine them by df<-do.call('rbind',your_list_data_frame) Then you can do what you want on the dataframe instead of a list HTH Weidong Gu On Fri, Oct 14, 2011 at 9:

Re: [R] getting data associated with coordinates in a spatial data frame

2011-10-13 Thread Weidong Gu
Because SpatialPointsDataFrame is S4 object, you may try index by @ e@coords or coordinates(e) Weidong Gu On Thu, Oct 13, 2011 at 2:18 PM, Bailey, Daniel wrote: > Michael, > Thank you for the tips. The suggestion didn't work though. Here is the output > of str(e):

Re: [R] Help with R plots

2011-10-12 Thread Weidong Gu
try hist(gender$HeartRate,main='Histogram: HeartRate distribution for Temperature Data') Weidong Gu On Wed, Oct 12, 2011 at 8:44 PM, Jonathan Edwin wrote: > Hi all, > > Mind my ignorance and complete newbiness, but I am very new to R and am > currently learning it thro

Re: [R] loop function within a loop

2011-10-12 Thread Weidong Gu
It's better to avoid loop in this situation. If you want to reorder subsets of the data based on event, the follow works df<-read.table('clipboard',header=TRUE) sp.or<-lapply(split(df,df$group),function(ldf) ldf[order(ldf$event),]) new.df<-do.call('rbind',sp.or)

Re: [R] CVbinary - Help

2011-10-12 Thread Weidong Gu
Maybe it was caused by your modeling binary variable using lm rather than glm. Weidong Gu On Wed, Oct 12, 2011 at 9:59 AM, anamiguita wrote: > Hey, > > I need some help. > > I want to obtain a cross validation for a regression model (binary response) > but I got an error wit

Re: [R] Mean or mode imputation fro missing values

2011-10-11 Thread Weidong Gu
In your case, it may not be sensible to simply fill missing values by mean or mode as multiple imputation becomes the norm this day. For your specific question, na.roughfix in randomForest package would do the work. Weidong Gu On Tue, Oct 11, 2011 at 8:11 AM, francesca casalino wrote: > Dea

Re: [R] Multiple imputation on subgroups

2011-10-10 Thread Weidong Gu
An ad-hoc method is to impute missing scores of the whole data set including subgroup1, then change imputed scores in subgroup1 into NA. Weidong Gu On Mon, Oct 10, 2011 at 5:35 AM, Sarah wrote: > Dear R-users, > > I want to multiple impute missing scores, but only for a few subgro

Re: [R] Advice in model construction

2011-10-06 Thread Weidong Gu
pair-wise comparison, you need post-hoc testing methods (?TukeyHSD). HTH Weidong Gu On Wed, Oct 5, 2011 at 1:55 PM, Chris Mcowen wrote: > Dear list, > > I am unsure how to structure my model, i have tried something and it makes > sense but i am unsure if i am interpreting it corr

Re: [R] Data transformation & cleaning

2011-09-28 Thread Weidong Gu
Seems your questions belong to rule mining for frequent item sets. check arules package Weidong Gu On Tue, Sep 27, 2011 at 11:13 PM, pip56789 wrote: > Hi, > > I have a few methodological and implementation questions for ya'll. Thank > you in advance for your help. I have a data

Re: [R] adding labels to x,y points

2011-09-21 Thread Weidong Gu
A sample data would help. But you could modify as text(x,y, label = row.names(colon[1:20,])) HTH Weidong Gu On Tue, Sep 20, 2011 at 7:43 PM, baumeist wrote: > Hi, > I am new to R. > > I have a matrix that I have assigned to the object “colon”. > >> colon<-read.table

Re: [R] A question regarding random effects in 'aov' function

2011-09-20 Thread Weidong Gu
If different labs tested different tissue.types, I am not sure you can effectively partition variance between labs(batches) and tissue.types. Weidong Gu On Tue, Sep 20, 2011 at 2:14 PM, karena wrote: > Hi, > > I am doing an analysis to see if these is tissue specific effects on t

Re: [R] plot(m, which = 1), where m is a lm linear model. What is 'which' doing?

2011-09-15 Thread Weidong Gu
Remember R is object-oriented. Your m is lm object, so check ?plot.lm Weidong Gu On Thu, Sep 15, 2011 at 8:14 PM, Idris Raja wrote: > Sample code from *R CookBook* (awesome book btw) *11.12: Finding the Best > Power Transformation (Box-Cox) Procedure* > > require(MASS) > x

Re: [R] Loops

2011-09-14 Thread Weidong Gu
ent the counter } } Weidong Gu On Wed, Sep 14, 2011 at 5:36 PM, Fred wrote: > Dear forum, > > I would like to forecast e.g. with the arima-model. To figure out which > model works best I am going to predict with this models. > > my first code: > > for(ar.ord in 1:3)

Re: [R] how to plot a series of data in a dataframe?

2011-09-01 Thread Weidong Gu
This can be done using bwplot in lattice library. Also, it is better to organize your data in 'long' format. Look at functions reshape or melt in reshape library. Weidong Gu On Thu, Sep 1, 2011 at 12:10 PM, Jie TANG wrote: > hi > > i have a dataframe with the name "obsd

Re: [R] reading data from multiple files with multiple headers

2011-08-31 Thread Weidong Gu
line where the character locates. Then, you can specify skip in read.table to input your data. HTH Weidong Gu On Tue, Aug 30, 2011 at 10:23 PM, Julius Tesoro wrote: > Dear All, > > > I have many files with a lot of headers and text at the beginning of the > file. The headers

Re: [R] locate the needed columns

2011-08-30 Thread Weidong Gu
nrow and ncol for (i in 1:3) { group.v[i,]<-names(d)[grep(LETTERS[i],names(d))] df[i]<-d[,names(d)%in% group.v[i]] } Weidong Gu On Tue, Aug 30, 2011 at 2:31 PM, Hui Du wrote: > > Hi All, > >                I have a data frame, whose colnames like "A.x, B.x, C.x, A.y,

Re: [R] column names with rbind loop

2011-08-30 Thread Weidong Gu
How about to add a conditional statement to get the header from 1st file for(i in all.files) { if (i==all.files[1]) new.data <- read.table(i,header=TRUE) else { new.data <- rbind(new.data, read.table(i))}} Weidong Gu On Tue, Aug 30, 2011 at 1:42 PM, Vining, Kelly wrote: > Hello

Re: [R] rpart: apply tree to new data to get "counts"

2011-08-29 Thread Weidong Gu
? predict.rpart Weidong Gu On Mon, Aug 29, 2011 at 12:49 PM, Jay wrote: > Hi, > > when I have made a decision tree with rpart, is it possible to "apply" > this tree to a new set of data in order to find out the distribution > of observations? Ideally I would like to pl

Re: [R] How to find the accuracy of the predicted glm model with family = binomial (link = logit)

2011-08-26 Thread Weidong Gu
Andra, You can transfer the probabilities into class membership by setting up a cut-off value, usually 0.5. set.seed(3) x<-rnorm(100) y<-rbinom(100,prob=1/(1+exp(x)),size=1) model<-glm(y~x,family=binomial(link=logit)) pred<-ifelse(predict(model,type='response')>0.5,1,0

Re: [R] Boxplot orders

2011-08-24 Thread Weidong Gu
At default, factors (months) are alphabetically leveled. You can explicitly re-level months months<-factor(months,levels=c('Jan','Feb','Mar',...,'Dec')) Then it should work. Weidong Gu On Wed, Aug 24, 2011 at 10:45 AM, Phoebe Jekielek wrote: > H

Re: [R] Linear Regression with 2 grouping variables

2011-08-22 Thread Weidong Gu
You can do something like this sp<-split(dat, list(dat$Vial,dat$Site)) seq.model<-lapply(sp, function(x) lm(x$InRFU~x$Time)) Then, extract whatever you want from seq.model Weidong Gu On Mon, Aug 22, 2011 at 9:15 PM, Nathan Miller wrote: > Hi all, > > I have a data set t

Re: [R] Dot plot with two grouping variables concurrently

2011-08-21 Thread Weidong Gu
in the places of pch in your codes of dotplot and key HTH Weidong Gu > My code so far is as follows: > > ## initalise > library("lattice") > > ##read the data to a variable > Cal_dat <- read.table("Calibration2.dat",header = TRUE,sep = "\t"

Re: [R] Groups and bwplot

2011-08-20 Thread Weidong Gu
You may want to consult a recent post by Felix (https://stat.ethz.ch/pipermail/r-help/2011-August/286707.html) on how to pass group parameter. Weidong Gu On Sat, Aug 20, 2011 at 6:59 AM, Sébastien Bihorel wrote: > Dear R-users, > > A while ago, Deepayan Sarkar suggested some code that

Re: [R] Auto key legend does not match plot

2011-08-19 Thread Weidong Gu
It is most likely due to your ordering of y values. You need to write key manually to reflect the change. Without providing reproduciable data, you may not get specific help. Weidong Gu On Fri, Aug 19, 2011 at 6:23 PM, markm0705 wrote: > Dear R-help members.  I am an 'R-learner' (

Re: [R] Excluding NAs from round correlation

2011-08-13 Thread Weidong Gu
check ?cor Please note the parameter 'use' Weidong Gu On Sat, Aug 13, 2011 at 9:06 AM, Julie wrote: > Hello, > I am quite new to R and I am trying to get a round correlation from a table > with dozens of columns. However, all the columns contain several blank > places w

Re: [R] sapply to bind columns, with repeat?

2011-08-12 Thread Weidong Gu
On Fri, Aug 12, 2011 at 5:08 PM, Katrina Bennett wrote: > Hi Weidong Gu, > > This works! For my clarity, and so I can repeat this process if need be: > > The 'mat' generates a matrix using whatever is supplied to x (i.e. > coop.dat) using the columns from position

Re: [R] sapply to bind columns, with repeat?

2011-08-12 Thread Weidong Gu
exactly what you want. Weidong Gu On Fri, Aug 12, 2011 at 2:35 AM, Katrina Bennett wrote: > Hi R-help, > > I am working with US COOP network station data and the files are > concatenated in single rows for all years, but I need to pull these > apart into rows for each day. To do t

Re: [R] using if then statements in a dataframe

2011-08-10 Thread Weidong Gu
Mike, One thing I noticed that '&&' should be replaced by '&'. The former is applied to the first element of the vector while the latter applicable to the whole vector. HTH Weidong Gu On Wed, Aug 10, 2011 at 7:34 PM, Ward, Michael Patrick wrote: > > I us

Re: [R] Classification trees problem.

2011-08-08 Thread Weidong Gu
?predict.rpart Weidong Gu On Mon, Aug 8, 2011 at 6:08 PM, Jose Bustos Melo wrote: > Hello Everyone, > > I'm doing a Classification trees with categorical explanatory variables using > library rpart and I would like to do a prediction for some data imputs. I > don't k

Re: [R] labelling a stacked barchart (lattice)

2011-08-04 Thread Weidong Gu
)-dta$x/2,1.3,labels=as.character(dta$y)) }) Weidong Gu On Wed, Aug 3, 2011 at 9:01 PM, M/K Zodet wrote: > All: > > Below is my code for creating a basic horizontal, stacked barchart.  I'd like > to label the plot in two ways:  1) place the x values in each piece and 2) > place the

Re: [R] sum part of a vector

2011-07-23 Thread Weidong Gu
Hi Simon, Is this what you want? mydat$cum.news<-unlist(tapply(mydat$news,mydat$state,FUN=cumsum)) Weidong Gu On Sat, Jul 23, 2011 at 7:11 AM, Simon Kiss wrote: > Dear colleagues, I have a data set that looks roughly like this; > mydat<-data.frame(state=c(rep("Alabama",

Re: [R] Extracting components from a 'boot' class output in R

2011-07-22 Thread Weidong Gu
Sarath, Maybe someone can show a direct access to the statistic. One way to get around is to access 't' component of the boot object which contains individual estimates. so you can extract standard error by sqrt(var(bootObj$t)) Weidong Gu On Fri, Jul 22, 2011 at 11:36 AM, Sar

Re: [R] Bootstrap

2011-07-20 Thread Weidong Gu
I didn't see bootstrap steps in your code. One way to modify your codes for (Ncount in 1:100) { b.data<-data[sample(1:nrow(data),replace=T),] y <-b.data[,1] x <-b.data[,2] n <- length(x) ... ### make appropriate changes if needed } Weidong Gu On Wed, Jul 20, 2011 at 6:09 PM,

Re: [R] Calculating mean from wit mice (multiple imputation)

2011-07-20 Thread Weidong Gu
Sarah, You can try this mean(sapply(1:n.imp, function(x) complete(imp,x)$y)) Weidong Gu On Wed, Jul 20, 2011 at 6:05 AM, Sarah wrote: > Hi all, > > How can I calculate the mean from several imputed data sets with the package > mice? > I know you can estimate regression param

Re: [R] calculating mean excluding zeros

2011-07-19 Thread Weidong Gu
You can do it by subsetting or indexing r<-c(0,0,0,rnorm(10,10,5)) > mean(r) [1] 8.052215 > mean(r[r!=0]) [1] 10.46788 Weidong Gu On Tue, Jul 19, 2011 at 4:36 PM, Dimitri Liakhovitski wrote: > Sorry if it's been discussed before - don't seem to find it. > I'd

Re: [R] error on my loop function

2011-07-16 Thread Weidong Gu
Hi, In your loop, change Corrs[i] to Corrs[i,] Weidong Gu On Sat, Jul 16, 2011 at 12:02 PM, EdBo wrote: >> t > Hi > > I have to matrices t and y below. I want correlation of columns (a,d) (b,e) > and (c,f). The correlation should be for the first 3 rows of  matrix t >

Re: [R] Repating a loop of lm function with different columns of database

2011-07-14 Thread Weidong Gu
If I understood your question x<-data.frame(matrix(rnorm(2000,10,10),ncol=50)) sapply(1:5,function(i) summary(lm(x[,i]~x[,i+10]+x[,50]))) Weidong Gu On Thu, Jul 14, 2011 at 2:27 PM, Jon Toledo wrote: > > Hi, > First let me thank you for the incredible help and resource that this

Re: [R] adding text to spplot

2011-07-13 Thread Weidong Gu
You may need panel function spplot(enaD2, "var1.pred",sp.layout=pts, main = "globina 60 cm", sub="D2", col.regions=terrain.colors(64), contour=T, panel = function(x,y,z,subscripts,...) { panel.polygonsplot(x,y,z,subscripts,...) sp.text(coordinates(enaD2), enaD2$ime

Re: [R] modification of cross-validations in rpart

2011-07-04 Thread Weidong Gu
One way around hacking rpart is to write code to do K fold samples based on unit outside rpart, then build trees using training sets and summarize scores on testing sets. Weidong Gu On Mon, Jul 4, 2011 at 9:22 AM, Katerine Goyer wrote: > > > > > > > > Hello, > &

Re: [R] How many times occurs

2011-07-03 Thread Weidong Gu
another way of thinking is to turn the sequences into strings if your data is db >apply(db,1,function(x) length(gregexpr('892',paste(c(x),collapse=''))[[1]])) [1] 1 3 1 1 3 2 Weidong Gu On Sat, Jul 2, 2011 at 3:40 PM, Trying To learn again wrote: > Hi all, >

Re: [R] Size argument in sample function

2011-06-17 Thread Weidong Gu
you can do something like this x<-rnorm(20,0,1) time=c(1,2,3) sapply(1:length(time),function(t) sample(x,time[t])) Weidong Gu On Fri, Jun 17, 2011 at 9:59 AM, alfredo wrote: > Hi All, > > I'd like to randomly sample a vector N times, where each successive random > sample

Re: [R] Linear model - coefficients

2011-06-12 Thread Weidong Gu
this may work. X<-data.frame(sapply(X,function(x) as.factor(x))) reg3=lm(Y~.,data=X) dummy.coef(reg3) Weidong Gu On Sun, Jun 12, 2011 at 4:55 PM, Robert Ruser wrote: > Hi, > but I want to get the coefficients for every variables from x1 to x5. > (x1 was an example) > > Ro

Re: [R] using categorical variable in multiple regression

2011-06-12 Thread Weidong Gu
for categorical independent variables, regression models in R will generate dummy indicators based on your setting of contrasts (default contr.treatment). Use model.matrix(your model) to see how R does this internally. Weidong Gu On Sun, Jun 12, 2011 at 2:38 AM, setlist wrote: > Hello, I wan

Re: [R] Counting the Number of Letters in a row

2011-06-10 Thread Weidong Gu
Is this what you want? sapply(sapply(strsplit(as.character(f1$keyword),' '),nchar),sum) Weidong Gu On Fri, Jun 10, 2011 at 1:25 PM, Jorge Ivan Velez wrote: > Hi Abraham, > > Try > > foo <- function(x){ > x <- as.character(x) >  sapply(strsplit(x, " &

Re: [R] merging/intersecting 2 data frames

2010-06-29 Thread Weidong Gu
Erin, ?merge Try c.df=merge(a.df,b.df,by.x="PATIENT_ID",by.y="ID") hope it helps Weidong __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html a

[R] how to draw two series in bwplot

2010-02-05 Thread Weidong Gu
this way, instead it plots addtions of the two columns. I changed allow.multiple with no success. Your help is appreciated. Weidong Gu Department of Medicine University of Alabama, Birmingham __ R-help@r-project.org mailing list https://stat.ethz.ch

[R] problems with arrangement of figures by layout function

2009-02-25 Thread Weidong Gu
nd the problem? Thanks in advance Weidong Gu Department of Medicine UAB __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide comm

Re: [R] why results from regression tree (rpart) are totallyinconsistent with ordinary regression

2009-02-23 Thread Weidong Gu
Hi Bert, Thanks for your prompt response. Yeah, summary() shows the correct answer, seemingly, plot() and text() reverse the direction of >= sign, a bit confusion. Weidong Gu -Original Message- From: Bert Gunter [mailto:gunter.ber...@gene.com] Sent: Monday, February 23, 2009 5:14

[R] why results from regression tree (rpart) are totally inconsistent with ordinary regression

2009-02-23 Thread Weidong Gu
+Deterrence)) indicates that Mortality was positively related to Incidence. How this unintuitive result? Advice is appreciated. Weidong Gu, Department of Medicine University of Alabama, Birmingham Deterrence Mortality Incidence 0.695 0.5166 0.255 0.501 48 0.612 0.483 55 0.209

[R] run optim() on a list

2008-09-07 Thread Weidong Gu
all without success. So, your help would be appreciated. Weidong Gu Department of Medicine University of Alabama, Birmingham 1900 University Blvd., Birmingham, Alabama 35294 Email: [EMAIL PROTECTED] PH: (205)-975-9053 Site Pool Positivity UBA_1 22 0 UBA_1 50 0 UBA_1 23 0

Re: [R] how can i sort a column of data.frame ?

2008-05-19 Thread Weidong Gu
? order df<-data.frame(a=rnorm(20),b=rpois(20,5),c=runif(20)) or<-order(df$b,decreasing=T) df.or<-df[or,] Weidong Gu Department of Medicine University of Alabama, Birmingham 1900 University Blvd., Birmingham, Alabama 35294 -Original Message- From: [EMAIL PROTECTED] [mail

Re: [R] substring

2008-05-06 Thread Weidong Gu
?gsub() Match the start (_) followed by anything (.*) and replace by "" gsub("_.*","",Name) Weidong Gu, Department of Medicine University of Alabama, Birmingham 1900 University Blvd., Birmingham, Alabama 35294 PH: (205)-975-9053 -Original Message- F

Re: [R] Deleting rows with missing data

2008-04-21 Thread Weidong Gu
?na.omit Weidong Gu, Department of Medicine University of Alabama, Birmingham 1900 University Blvd., Birmingham, Alabama 35294 Email: [EMAIL PROTECTED] PH: (205)-975-9053 -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Charles Vetterli Sent: Monday

  1   2   >