[R] nls model definition help

2013-10-22 Thread Wayne.W.Jones
Hi fellow R users, I'm trying to fit a model using nls with the following model definition: y(t+1)=(th1*x1 + R1*x2) * exp(a1*x3) + (1-th1*x1 + R1*x2)*y(t) y is the dependent variable (note on both sides of eq) and the x's represent the regressors. th1, R1 and a1 are parameters to be estimated.

Re: [R] Splines

2007-10-05 Thread Wayne.W.Jones
smooth.spline is a handy function and does what you need: Careful to not over fit though. Use different values of spar and df. y<-c(467, 468, 460 ,460 ,450, 432, 419, 420, 423, 423) x<-1:10 plot(x,y) predict(smooth.spline(x,y,df=4),x=3.5) lines(predict(smooth.spline(x,y,df=4),x=seq(1,10,length=1

Re: [R] function for special matrix design

2007-10-02 Thread Wayne.W.Jones
Lookup: ?diag ?upper.tri ?lower.tri Example: my.mat<-matrix(1:16,ncol=4) my.mat my.mat[upper.tri(my.mat)]<-3 my.mat -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of kevinchang Sent: 01 October 2007 17:37 To: r-help@r-project.org Subject: [R] function for

Re: [R] xyplot

2007-10-01 Thread Wayne.W.Jones
When you call xyplot in a for loop you have to use the print command. For instance modifying the xyplot example: The following wont work: Depth <- equal.count(quakes$depth, number=8, overlap=.1) for(i in 1:3){xyplot(lat ~ long | Depth, data = quakes)} But this will: for(i in 1:3){print(x

Re: [R] export csv

2007-10-01 Thread Wayne.W.Jones
Following on from your example: write.table(M,file="Myfile.csv",sep=",",row.names=F) -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Yves Moisan Sent: 01 October 2007 14:45 To: r-help@r-project.org Subject: Re: [R] export csv Hello, I wanna know how

Re: [R] Concatenating one character vector into one string

2007-10-01 Thread Wayne.W.Jones
x <- c("This ", "is ", "one ", "sentence.") paste(x,collapse="") -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Rainer M. Krug Sent: 01 October 2007 13:23 To: r-help Subject: [R] Concatenating one character vector into one string Hi I am sure this is si

Re: [R] 3-dimensional graph

2007-10-01 Thread Wayne.W.Jones
Hi there, you could try: library(scatterplot3d) THese function are also quite handu for visualising 3d images in 2d by virtue of contours, heat maps etc.. ?image ?persp ?contour -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of John Sorkin Sent: 01 October

Re: [R] Need help with function writing

2007-09-27 Thread Wayne.W.Jones
Why dont you use the t.test within R? See help(t.test). It looks to have everything you need: here are the examples with different alternative hypothesese: with(sleep, t.test(extra[group == 1], extra[group == 2],alternative = "greater")) with(sleep, t.test(extra[group == 1], extra[group == 2],

Re: [R] Getting group-wise standard scores of a vector

2007-09-26 Thread Wayne.W.Jones
tapply is also very useful: my.df<-data.frame(x=rnorm(20, 50, 10),group=factor(sort(rep(c("A", "B"), 10 tapply(my.df$x,my.df$group,function(x){(x-mean(x))/sd(x)}) -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Matthew Dubins Sent: 26 September 2007

Re: [R] RODBC problem

2007-09-26 Thread Wayne.W.Jones
Not sure which of the questions yo want answered in your email. However, if its the one regarding the boxplot try: dd <- read.table("test.txt",header=T) attach(dd) boxplot(x) outlier <- function(y){ out <- boxplot(y, range = 1)$out outliers <- which(y %in% out) return(list(out=out,outliers=

Re: [R] finding a stable cluster for kmeans

2007-09-25 Thread Wayne.W.Jones
Hi there, If the final predicted clusters vary according to a random starting cluster then I suspect that your data is not clustering very well!! A few reasons for this may be: 1) There are genuinely no clusters in the data! 2) You have chosen a poor distance measure. 3) You have picked an i

Re: [R] 10- fold cross validation for naive bayes(e1071)

2007-09-25 Thread Wayne.W.Jones
Hi there, The tune function is extremely useful for quickly cross validating a model. However, you often need to modify some of the predict functions. Here is an example of tuning an svm and naiveBayes with the iris data set: naiveBayes: For some reason the naivebayes predict function (g

Re: [R] Performance problems to fill up a dataframe

2007-09-24 Thread Wayne.W.Jones
Use table: dat <- data.frame(c(60001,60001,60050,60050,60050),c(27,129,618,27,1579)) table(dat[,1],dat[,2]) 27 129 618 1579 60001 1 1 00 60050 1 0 11 Regards Wayne -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of F

Re: [R] Calculate difference between dates in years

2007-09-24 Thread Wayne.W.Jones
look at the as.Date function e.g. as.Date("2007-04-21")- as.Date("2000-04-21") also look at the chron library. Regards Wayne -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Daniel Brewer Sent: 24 September 2007 11:23 To: [EMAIL PROTECTED] Subject: [R

Re: [R] xyplot question

2007-09-19 Thread Wayne.W.Jones
The following link is an excellent reference which gives R code for making different plots in R. http://addictedtor.free.fr/graphiques/thumbs.php Is it something like this you want: http://addictedtor.free.fr/graphiques/RGraphGallery.php?graph=52 The code can be found to do this on the webp

Re: [R] Comparing regression models

2007-09-14 Thread Wayne.W.Jones
I would suggest doing an F-test.A descrition is given here: http://www.graphpad.com/curvefit/2_models__1_dataset.htm. The method is valid becasue one of your models is a subset of another. Correct use of the anova function does indeed perform this test. For example: data(airquality) lm1<-l

Re: [R] How to remove index from list after split?

2007-09-14 Thread Wayne.W.Jones
Not sure what you mean by "group index" but try: lapply(df.s,function(l){l$x}) or something like: do.call("rbind",df.s) to convert the result into a data.frame. Regards Wayne -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Rick DeShon Sent: 14 Sept

Re: [R] Logistic regression

2007-09-14 Thread Wayne.W.Jones
Google search "Logistic Regression using R" There are loads of good links here. Basically you use a generalized linear model. Look up ?glm Regards Wayne -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of martin pareja Sent: 13 September 2007 16:33 To: r-he

[R] test

2007-09-13 Thread Wayne.W.Jones
Testing if I can mail to the list! None of my emails seem to be getting through. Apologies. Wayne Jones Statistical Consultant Shell Global Solutions (UK) Shell Technology Centre Thornton, P.O. Box 1, Cheste

Re: [R] Bootstrap tree selection in rpart

2007-09-13 Thread Wayne.W.Jones
Hi there, Rather than cross validating or bootstrapping to prune a single tree you could use random forest instead. Look at the overview in http://www.stat.berkeley.edu/~breiman/RandomForests/cc_home.htm THere is a package in R for doing this called library(randomForest). I have found it to

Re: [R] how to plot shaded area under a curve?

2007-09-13 Thread Wayne.W.Jones
?polygon -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of gallon li Sent: 13 September 2007 11:52 To: r-help Subject: [R] how to plot shaded area under a curve? say, I am plotting x=seq(0,5,len=100) y=-(x-5)^2 plot(x,y) how can I put some color or ver

Re: [R] how to plot shaded area under a curve?

2007-09-13 Thread Wayne.W.Jones
?polygon -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of gallon li Sent: 13 September 2007 11:52 To: r-help Subject: [R] how to plot shaded area under a curve? say, I am plotting x=seq(0,5,len=100) y=-(x-5)^2 plot(x,y) how can I put some color or verti

Re: [R] pick time intervalls

2007-09-13 Thread Wayne.W.Jones
?tapply temp.data<-data[as.character(data$time %in% c("02:00","03:00","04:00"),] # one quick and dirty method is to create a subset the data , not sure what format your time data is so converted to character strings. then something like: tapply(temp.data$V1, factor(temp.data$time), mean) W

Re: [R] Multivariate, multilevel regression?

2007-09-13 Thread Wayne.W.Jones
Hi John, It sounds like what you need is a mixed effects model. This will allow you to model effects which apply to the whole population (fixed effects) and those which are specific to an individual (random effects).The theory and practice of mixed effects models is too large to discuss fully