[R] fitting t copula
Hi r-users, I try to fit the t copula using the gamma marginals. But I got error message which I don't really understand. Thank you for any help given. myCop.t - ellipCopula(family = t, dim = 2, dispstr = toep, param = 0.5, df = 8) myCop.t myMvd - mvdc(copula = myCop.t, margins = c(gamma, gamma), paramMargins = list(list(mean = 0, sd = 2), list(mean = 0, sd = 1))) myMvd dat - stn_pos ## observed data loglikMvdc(c(0, 2, 0, 1, 0.5,8), dat, myMvd)  ## loglikelihood mm - apply(dat, 2, mean) vv - apply(dat, 2, var) rho - rcorr(stn_pos,type=spearman)[[1]]; round(rho,2) rbind(mm,vv) b1.0 - c(mm[1]^2/vv[1], vv[1]/mm[1]) b2.0 - c(mm[2]^2/vv[2], vv[2]/mm[2]) a.0 - sin(cor(dat[, 1], dat[, 2], method = kendall) * pi/2) start - c(b1.0, b2.0, a.0) fit - fitMvdc(dat, myMvd, start = start,optim.control = list(trace = TRUE, maxit = 2000)) fit # head(dat);tail(dat)      [,1] [,2] [1,] 28.4 43.5 [2,]  9.2  7.4 [3,] 48.8 68.9 [4,] 185.2 115.7 [5,]  4.1 11.7 [6,] 67.6 29.8        [,1] [,2] [946,]  8.8 17.2 [947,] 119.6 164.0 [948,] 68.4 163.6 [949,] 45.8 61.6 [950,] 77.0 101.0 [951,] 56.6 74.8 myCop.t - ellipCopula(family = t, dim = 2, dispstr = toep, param = 0.5, df = 8) myCop.t t copula family Dimension: 2 Parameters:   rho.1 = 0.5   df = 8 myMvd - mvdc(copula = myCop.t, margins = c(gamma, gamma), paramMargins = list(list(mean = 0, sd = 2), list(mean = 0, sd = 1))) myMvd An object of class âmvdcâ Slot copula: t copula family Dimension: 2 Parameters:   rho.1 = 0.5   df = 8 Slot margins: [1] gamma gamma Slot paramMargins: [[1]] [[1]]$mean [1] 0 [[1]]$sd [1] 2 [[2]] [[2]]$mean [1] 0 [[2]]$sd [1] 1 Slot marginsIdentical: [1] FALSE dat - stn_pos ## observed data loglikMvdc(c(0, 2, 0, 1, 0.5,8), dat, myMvd)  ## loglikelihood Error in pgamma(x, mean = 0, sd = 2) :  unused argument(s) (mean = 0, sd = 2) [1] NaN mm - apply(dat, 2, mean) vv - apply(dat, 2, var) rho - rcorr(stn_pos,type=spearman)[[1]]; round(rho,2)     [,1] [,2] [1,] 1.0 0.9 [2,] 0.9 1.0 rbind(mm,vv)         [,1]     [,2] mm  58.63912  83.7224 vv 1789.51116 3315.2367 b1.0 - c(mm[1]^2/vv[1], vv[1]/mm[1]) b2.0 - c(mm[2]^2/vv[2], vv[2]/mm[2]) a.0 - sin(cor(dat[, 1], dat[, 2], method = kendall) * pi/2) start - c(b1.0, b2.0, a.0) fit - fitMvdc(dat, myMvd, start = start,optim.control = list(trace = TRUE, maxit = 2000)) Error in fitMvdc(dat, myMvd, start = start, optim.control = list(trace = TRUE, :  The length of start and mvdc parameters do not match. [[alternative HTML version deleted]] __ 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 commented, minimal, self-contained, reproducible code.
[R] set x11 as default plot
Dear all, I am looking for a a way to set x11 as a default plotting engine instead of quartz, which I had some troubles with. If I just called it, like x11() an x11 window pops up and plots every graph that is called since then. Though I do not want to invoke it manually. I mean I do not have to use quartz() either before plotting. Thx in advance for any suggestions! best matt __ 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 commented, minimal, self-contained, reproducible code.
Re: [R] how to read CSV file in R?
If you have memory problems reading csv you can use read.csv.ffdf from package ff which reads in chunks. The result is a ffdf object, say myffdf, from which binary subscripting [,] returns standard data.frames, such as myffdf[,] # returns all data (if it fits into memory) myffdf[somerows,] # returns a subset of data Do read and understand the help concerning filename location and implications for finalizers and permanency. Cheers Jens Oehlschlägel -Ursprüngliche Nachricht- Von: Joris Meys jorism...@gmail.com Gesendet: Jun 8, 2010 1:11:20 PM An: dhanush dhana...@gmail.com Betreff: Re: [R] how to read CSV file in R? That will be R 2.10.1 if I'm correct. For reading in csv files, there's a function read.csv who does just that: los - read.csv(file.csv,header=T) But that is just a detail. You have problems with your memory, but that's not caused by the size of your dataframe. On my system, a matrix with 100,000 rows and 75 columns takes only 28 Mb. So I guess your workspace is cluttered with other stuff. Check following help pages : ?Memory ?memory.size ?Memory.limits it generally doesn't make a difference, but sometimes using gc() can set some memory free again. If none of this information helps, please provide us with a bit more info regarding your system and the content of your current workspace. Cheers Joris On Tue, Jun 8, 2010 at 8:46 AM, dhanush dhana...@gmail.com wrote: I tried to read a CSV file in R. The file has about 100,000 records and 75 columns. When used read.delim, I got this error. I am using R ver 10.1. los-read.delim(file.csv,header=T,sep=,) Warning message: In scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, : Reached total allocation of 1535Mb: see help(memory.size) Thanks -- View this message in context: http://r.789695.n4.nabble.com/how-to-read-CSV-file-in-R-tp2246930p2246930.html Sent from the R help mailing list archive at Nabble.com. __ 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 commented, minimal, self-contained, reproducible code. -- Joris Meys Statistical consultant Ghent University Faculty of Bioscience Engineering Department of Applied mathematics, biometrics and process control tel : +32 9 264 59 87 joris.m...@ugent.be --- Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php __ 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 commented, minimal, self-contained, reproducible code. __ 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 commented, minimal, self-contained, reproducible code.
[R] VaR using monte carlo simulation
Sir, I want to calculate VaR (Value at Risk) using Monte Carlo Simulation in R.Is there any function in R to calculate Var ?. Can you give me an eaxmple. Thanks Regards, Suman Dhara [[alternative HTML version deleted]] __ 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 commented, minimal, self-contained, reproducible code.
[R] Highlighting Text in Console
Anyone know how I can highlight specific words/letters (e.g., bold, or different colour) when displaying text to the console using cat or equivalent? I can change e.g., the colour for everything by loading in a new Rconsole file, but what I really want to do is write hello world to the screen but with the word world highlighted in some way. I've searched the Web, the R manuals and the FAQ's but not found anything yet. Any help greatly appreciated. Thanks. [[alternative HTML version deleted]] __ 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 commented, minimal, self-contained, reproducible code.
Re: [R] scatterplot function - double check: dashed lines
On 06/08/2010 08:44 PM, K F Pearce wrote: Hello everyone, This is just a quick double check. It concerns the 'scatterplot function' in R. I have 6 curves and I wish to represent each of them by a different kind of line (their colour must be black). The curves are derived from the cuminc function...the coordinates of which are in 'xx'. Upon reading the documentation in R, it looks like I can use the 'on/off' command for lty and I can merely run: plot(xx,color=black,lty=c(11,13,1343,73,2262,35)) according to the documentation, 13 (for example) means 1 'on' and 3 'off' . Does the above look OK ? Say, in another study, I wish to draw my 6 lines all in different colours (solid lines), I suppose that I could type: plot(xx, color=c(red,black,purple,yellow,brown,violet), lty=1) Hi Kim, It depends upon what the object(s) are that contain the values for the curves. If these are in a matrix or data frame, you would probably want: plot(xx[,1],type=l,lty=11) lines(xx[,2],lty=13) Although I agree with Greg, and find myself scratching my glabella in confusion when I have to decipher plots like that. If the lines are separated at the right edge of the plot, you might try leaving some extra margin there and labeling them as Greg suggested. You can get a combination of these effects with something like this: matplot(cbind(sort(rnorm(10)),sort(rnorm(10))),col=2:3,type=b) Jim __ 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 commented, minimal, self-contained, reproducible code.
Re: [R] Highlighting Text in Console
It depends what you mean by console. The package xterm256 on CRAN can do some of that on xterm 256 capable consoles. See http://bit.ly/97cCbX Romain Le 09/06/10 10:50, Steve Brooks a écrit : Anyone know how I can highlight specific words/letters (e.g., bold, or different colour) when displaying text to the console using cat or equivalent? I can change e.g., the colour for everything by loading in a new Rconsole file, but what I really want to do is write hello world to the screen but with the word world highlighted in some way. I've searched the Web, the R manuals and the FAQ's but not found anything yet. Any help greatly appreciated. Thanks. -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://bit.ly/98Uf7u : Rcpp 0.8.1 |- http://bit.ly/c6YnCi : graph gallery collage `- http://bit.ly/bZ7ltC : inline 0.3.5 __ 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 commented, minimal, self-contained, reproducible code.
Re: [R] Highlighting Text in Console
Thanks, I guess my WinXP console isn't xterm 256 capable. Any other thoughts? -Original Message- From: Romain Francois [mailto:romain.franc...@dbmail.com] Sent: 09 June 2010 09:57 To: Steve Brooks Cc: r-help@r-project.org Subject: Re: [R] Highlighting Text in Console It depends what you mean by console. The package xterm256 on CRAN can do some of that on xterm 256 capable consoles. See http://bit.ly/97cCbX Romain Le 09/06/10 10:50, Steve Brooks a écrit : Anyone know how I can highlight specific words/letters (e.g., bold, or different colour) when displaying text to the console using cat or equivalent? I can change e.g., the colour for everything by loading in a new Rconsole file, but what I really want to do is write hello world to the screen but with the word world highlighted in some way. I've searched the Web, the R manuals and the FAQ's but not found anything yet. Any help greatly appreciated. Thanks. -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://bit.ly/98Uf7u : Rcpp 0.8.1 |- http://bit.ly/c6YnCi : graph gallery collage `- http://bit.ly/bZ7ltC : inline 0.3.5 __ 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 commented, minimal, self-contained, reproducible code.
Re: [R] combining expressions in mathplot
On 09.06.2010 06:15, RICHARD M. HEIBERGER wrote: Is there a cleaner way of combining two expressions. This example works and gives what I want plot(1:10) aa- expression(alpha==.05) bb- expression(beta ==.80) aabb- expression(alpha==.05 ~ , ~ beta ==.80) text(5, 10, aa) text(5, 9, bb) text(5, 8, aabb) text(5,1, parse(text=paste(deparse(aa[[1]]), deparse(bb[[1]]), sep=~))) text(5, 1, substitute(a ~ b, list(a=aa[[1]], b=bb[[1]]))) text(5,2, parse(text=paste(deparse(aa[[1]]), deparse(bb[[1]]), sep=~', '~))) text(5, 1, substitute(a ~'~ b, list(a=aa[[1]], b=bb[[1]]))) Uwe Is there a cleaner way of combining the expressions aa and bb to get the effect of the last two lines? [[alternative HTML version deleted]] __ 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 commented, minimal, self-contained, reproducible code. __ 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 commented, minimal, self-contained, reproducible code.
[R] equivalent of stata command in R
Dear all, I need to use R for one estimation, and i have readily available stata command, but i need also the R version of the same command. the estimation in stata is as following: 1. Compute mean values of relevant variables . sum inno lnE lnM Variable | ObsMeanStd. Dev. MinMax -+ inno |146574.0880374.2833503 0 1 lnE |146353.92562391.732912 -4.473922 10.51298 lnM |1462094.2819031.862192 -4.847253 13.71969 2. Estimate model . xi: xtreg lnLP lnC lnL lnE lnM eco inno eco_inno eco_lnE eco_lnM i.year, fe i(stno) i.year_Iyear_1997-1999(naturally coded; _Iyear_1997 omitted) Fixed-effects (within) regression Number of obs =146167 Group variable (i): stnoNumber of groups = 48855 R-sq: within = 0.9908 Obs per group: min = 1 between = 0.9122avg = 3.0 overall = 0.9635max = 3 F(11,97301)= 949024.29 corr(u_i, Xb) = 0.2166 Prob F =0. -- lnLP | Coef. Std. Err. tP|t| [95% Conf. Interval] -+ lnC | .0304896 .000950932.06 0.000 .0286258.0323533 lnL | -.9835998 .0006899 -1425.74 0.000 -.984952 -.9822476 lnE | .0652658 .000943969.14 0.000 .0634158.0671159 lnM | .6729931 .0012158 553.53 0.000 .67061.6753761 eco | .0610348 .0177048 3.45 0.001 .0263336 .095736 inno | .0173824 .0058224 2.99 0.003 .0059706.0287943 eco_inno | .0080325 .0110815 0.72 0.469-.0136872.0297522 eco_lnE | .0276226.004059 6.81 0.000 .019667.0355781 eco_lnM | -.0214237 .0039927-5.37 0.000-.0292494 -.0135981 _Iyear_1998 | -.0317684 .0013978 -22.73 0.000 -.034508 -.0290287 _Iyear_1999 | -.0647261 .0027674 -23.39 0.000-.0701501 -.0593021 _cons | 1.802112.009304 193.69 0.000 1.7838761.820348 -+ sigma_u | .38142386 sigma_e | .2173114 rho | .75494455 (fraction of variance due to u_i) -- F test that all u_i=0: F(48854, 97301) = 3.30Prob F = 0. 3. Compute marginal effect of eco at sample mean . nlcom (_b[eco]+_b[inno]*.0880374+_b[eco_lnE]*.9256239+_b[eco_lnM]*4.281903) _nl_1: _b[eco]+_b[inno]*.0880374+_b[eco_lnE]*.9256239+_b[eco_lnM]*4.281903 -- lnLP | Coef. Std. Err. tP|t| [95% Conf. Interval] -+ _nl_1 | -.0036011.008167-0.44 0.659-.0196084.0124061 -- in fact i can find the mean of the variables ( step 1) and extimate the model (step 2) but i couldnt find the equivalent of step 3 (compute marginal effect of eco at sample mean). Can someone help me for this issue? Cheers! _ [[alternative HTML version deleted]] __ 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 commented, minimal, self-contained, reproducible code.
Re: [R] iterating over groups of columns
Seems to get complicated ;-) As always, i expect more sophisticted solutions than mine to exist, but I would try the following: If II understood you correct you want to compute the means of all the k.1.x, then k.2.x ., correct? I would do it this way col.index - sub('[.].*$','',sub('^.?[.]','',colnames(the.data))) min.values=numeric(length=10) for (i in 1:10) min[i]-min(the.data[,col.index==i]) Perhaps you have to adapt the code slightly as I did not test it. HTH Jannis col.index - unlist(strsplit(colnames(the.data),'\\.'))[2] --- 09wkj bill.k.jan...@williams.edu schrieb am Di, 8.6.2010: Von: 09wkj bill.k.jan...@williams.edu Betreff: Re: [R] iterating over groups of columns An: r-help@r-project.org CC: Jannis bt_jan...@yahoo.de Datum: Dienstag, 8. Juni, 2010 22:32 Uhr In the code fragment, I used 'by' to actually compute the min value (part of the statement with the eval) - and I agree that an apply would work there wonderfully. However, my hope was to use an apply for the subsetting of the data.frame's columns, so that I could then use an apply to compute the min across each row of the subsets. Something that would give me the results of the following, but programmatically: apply(the.data[,1], 1, min) #min of the first column apply(the.data[,2:3], 1, min) #min of the next 2 columns apply(the.data[,4:6], 1, min) #min of the next 3 columns apply(the.data[,7:10], 1, min) #min of the next 4 columns ... apply(the.data[,46:55], 1, min)#min of the next 10 columns Like, can I make a vector of levels with 'rep(1:10,1:10)', and then apply the function across all columns in each level? And then how could I cbind them together? Thanks for any help, Bill On Jun 8, 2010, at 5:08 PM, Jannis wrote: you should have found a solution for that in the help page of apply. just run min.values = apply(the.data,1,min) the '1' marks the direction (e.g. whether apply is applied to rows or columns), it could be a 2 as well. Check that yourself in the apply documentation. Then run rbind(the.data,min.values) (could be cbind as well, I am not sure again ;-) ) and you get what you want. 09wkj schrieb: I am mainly a Java/C++ programmer, so my mind is used to iterating over data with for loops. After a long break, I am trying to get back into the R mindset, but I could not find a solution in the documentation for the applys, aggregate, or by. I have a data.frame where each row is an entry with 10 groups of measurements. The first measurement spans 1 column, the second spans 2 columns, third 3, and so on (55 total columns). What I want to do is add to my data.frame 10 new columns containing the minimum value of each measurement. dim(the.data) [1] 1679 55 colnames(the.data) [1] k.1.1 k.2.1 k.2.2 k.3.1 k.3.2 k.3.3 k.4.1 [8] k.4.2 k.4.3 k.4.4 k.5.1 k.5.2 k.5.3 k.5.4 [15] k.5.5 k.6.1 k.6.2 k.6.3 k.6.4 k.6.5 k.6.6 [22] k.7.1 k.7.2 k.7.3 k.7.4 k.7.5 k.7.6 k.7.7 [29] k.8.1 k.8.2 k.8.3 k.8.4 k.8.5 k.8.6 k.8.7 [36] k.8.8 k.9.1 k.9.2 k.9.3 k.9.4 k.9.5 k.9.6 [43] k.9.7 k.9.8 k.9.9 k.10.1 k.10.2 k.10.3 k.10.4 [50] k.10.5 k.10.6 k.10.7 k.10.8 k.10.9 k.10.10 I want to add to the.data new columns: min.k.1, min.k.2, ..., min.k.10 This is the section of code I would like to improve, hopefully getting rid of the eval and the for loop: for(k in 1:10){ s - subset(the.data, select=paste(k, k, 1:k, sep=.)) eval(parse(text = paste(the.data$min.k., k, -as.vector(by(s, 1:nrow(s), min)), sep=))) } Thanks for any help, Bill __ 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 commented, minimal, self-contained, reproducible code. __ 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 commented, minimal, self-contained, reproducible code.
Re: [R] how to ignore rows missing arguments of a function when creating a function?
It's difficult to help you if we don't know what the data looks like. Two more tips : - look at ?with instead of attach(). The latter causes a lot of trouble further on. - use require() instead of library(). See also the help files on this. I also wonder what you're doing with the na.rm=TRUE. I don't see how it affects the function, as it is used nowhere. Does it really remove NA? This said: estfun takes the estimation function from your model object. Your model is essentially fit on all observations that are not NA, whereas I presume your cluster contains all observations, including NA. Now I don't know what kind of model fm represents, but normally there is information in the model object about the removed observations. I illustrate this using lm : x - rnorm(100) y - c(rnorm(90),NA,rnorm(9)) test - lm(x~y) str(test) List of 13 ... (tons of information) $ model:'data.frame': 99 obs. of 2 variables: ... (more tons of information) ..- attr(*, na.action)=Class 'omit' Named int 91 .. .. ..- attr(*, names)= chr 91 - attr(*, class)= chr lm Now we know that we can do : not -attr(test$model,na.action) y[-not] So try this ### NOT TESTED cl - function(dat, na.rm = TRUE, fm, cluster){ require(sandwich) require(lmtest) not - attr(fm$model,na.action) cluster - cluster[-not] with( dat ,{ M - length(unique(cluster)) N - length(cluster) K - fm$rank dfc - (M/(M-1))*((N-1)/(N-K)) uj - data.frame(apply(estfun(fm),2, function(x) data.frame(tapply(x, cluster, sum)) ) ); vcovCL - dfc*sandwich(fm, meat=crossprod(uj)/N) coeftest(fm, vcovCL) } ) } Cheers Joris On Wed, Jun 9, 2010 at 12:06 AM, edmund jones edmund.j.jo...@gmail.com wrote: Hi, I am relatively new to R; when creating functions, I run into problems with missing values. I would like my functions to ignore rows with missing values for arguments of my function) in the analysis (as for example is the case in STATA). Note that I don't want my function to drop rows if there are missing arguments elsewhere in a row, ie for variables that are not arguments of my function. As an example: here is a clustering function I wrote: cl - function(dat, na.rm = TRUE, fm, cluster){ attach( dat , warn.conflicts = F) library(sandwich) library(lmtest) M - length(unique(cluster)) N - length(cluster) K - fm$rank dfc - (M/(M-1))*((N-1)/(N-K)) uj - data.frame(apply(estfun(fm),2, function(x) data.frame(tapply(x, cluster, sum)) ) ); vcovCL - dfc*sandwich(fm, meat=crossprod(uj)/N) coeftest(fm, vcovCL) } When I run my function, I get the message: Error in tapply(x, cluster, sum) : arguments must have same length If I specify instead attach(na.omit(dat), warn.conflicts = F) and don't have the na.rm=TRUE argument, then my function runs; but only for the rows where there are no missing values AT ALL; however, I don't care if there are missing values for variables on which I am not applying my function. For example, I have information on children's size; if I want regress scores on age and parents' education, clustering on class, I would like missing values in size not to interfere (ie if I have scores, age, parents' education, and class, but not size, I don't want to drop this observation). I tried to look at the code of lm to see how the na.action part works, but I couldn't figure it out... This is exactly how I would like to deal with missing values. I tried to write cl - function(dat, fm, cluster, na.action){ attach( dat , warn.conflicts = F) library(sandwich) library(lmtest) M - length(unique(cluster)) N - length(cluster) K - fm$rank dfc - (M/(M-1))*((N-1)/(N-K)) uj - data.frame(apply(estfun(fm),2, function(x) data.frame(tapply(x, cluster, sum)) ) ); vcovCL - dfc*sandwich(fm, meat=crossprod(uj)/N) coeftest(fm, vcovCL) } attr(cl,na.action) - na.exclude but it still didn't work... Any ideas of how to deal with this issue? Thank you for your answers! Edmund [[alternative HTML version deleted]] __ 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 commented, minimal, self-contained, reproducible code. -- Joris Meys Statistical consultant Ghent University Faculty of Bioscience Engineering Department of Applied mathematics, biometrics and process control tel : +32 9 264 59 87 joris.m...@ugent.be --- Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php __ 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 commented, minimal, self-contained, reproducible code.
[R] Odp: Extracting Elements By Date
Hi You have got several suggestions. When I try your code I get only errors, not list or any other objects. x-unique(Returns.names$date_) Error in unique(Returns.names$date_) : object 'Returns.names' not found n-1 while(n=19) { + Returns.period-lapply(((n-1)*125+1):((n+1)*125), function (i) + which(Returns.filter$date_==x[i])) + Returns.period-unlist(Returns.period) + + Returns.period1[n,1:(length(Returns.period))]-Returns.filter[Returns.period,] + n-n+1 + } Error in which(Returns.filter$date_ == x[i]) : object 'Returns.filter' not found How do you expect to get reasonable help if you can not present what you did and how result differ from what you want on some fake data which we can copy to R. r-help-boun...@r-project.org napsal dne 09.06.2010 03:49:37: Dear R Gurus, Thanks for any help in advance! Date.frame: Returns.names X id ticker date_ adjClose totret RankStk 258060 258060 13645T10 CP 2001-06-29 18.125 1877.758 My data frame is in the above format. I would like to filter by period, per what is filter?? Help page says Description Applies linear filtering to a univariate time series or to each series separately of a multivariate time series. id (every 125 days) each consisting of 250 days, I.e. 1-250, 126-375, etc. snip Thus, I tried to adjust by dynamically assigning each period to a column. However, I get the error: object 'Returns.period1' not found. And R is not like Java where you can simply declare a variable by typing say Returns.period1. Why do you expect that one language will behave the same way as another language. If R was like Java what would be the reason to have 2 languages? Try instead to comply posting guide and make a fake data which can be directly used e.g. by dput, construct a result which is to be achieved and present a code which can be copied to R and which gives other then expected result. After that we can quit guessing and start providing relevant help. Regards Petr I do not know how to create a flexible empty matrix that would allow this code to work. If anyone knows how to do this without a loop, that would be even better! ##Filtering by Period n-1 while(n=19) { Returns.period-lapply(((n-1)*125+1):((n+1)*125), function (i) which(Returns.filter$date_==x[i])) Returns.period-unlist(Returns.period) Returns.period1[n,1:(length(Returns.period))]-Returns.filter[Returns.period,] n-n+1 } -- View this message in context: http://r.789695.n4.nabble.com/Extracting- Elements-By-Date-tp2248227p2248227.html Sent from the R help mailing list archive at Nabble.com. __ 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 commented, minimal, self-contained, reproducible code. __ 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 commented, minimal, self-contained, reproducible code.
Re: [R] equivalent of stata command in R
It helps if you translate the Stata commands. Not everybody is fluent in those. It would even help more if you would enlight us about the function you used to fit the model. Getting the marginal effects is not that hard at all, but how depends a bit on the function you used to estimate the model. You can try predict(your_model,type=terms,terms=the_term_you're_interested_in) For exact information, look at the respective predict function, eg if you use lme, do ?predict.lme Be aware of the fact that R normally choses the correct predict function without you having to specify it. predict() works for most model objects. Yet, depending on the model eacht predict function can have different options or different functionality. That information is in the help files of the specific function. Cheers Joris On Wed, Jun 9, 2010 at 11:28 AM, mike mick saint-fi...@hotmail.com wrote: Dear all, I need to use R for one estimation, and i have readily available stata command, but i need also the R version of the same command. the estimation in stata is as following: 1. Compute mean values of relevant variables . sum inno lnE lnM Variable | Obs Mean Std. Dev. Min Max -+ inno | 146574 .0880374 .2833503 0 1 lnE | 146353 .9256239 1.732912 -4.473922 10.51298 lnM | 146209 4.281903 1.862192 -4.847253 13.71969 2. Estimate model . xi: xtreg lnLP lnC lnL lnE lnM eco inno eco_inno eco_lnE eco_lnM i.year, fe i(stno) i.year _Iyear_1997-1999 (naturally coded; _Iyear_1997 omitted) Fixed-effects (within) regression Number of obs = 146167 Group variable (i): stno Number of groups = 48855 R-sq: within = 0.9908 Obs per group: min = 1 between = 0.9122 avg = 3.0 overall = 0.9635 max = 3 F(11,97301) = 949024.29 corr(u_i, Xb) = 0.2166 Prob F = 0. -- lnLP | Coef. Std. Err. t P|t| [95% Conf. Interval] -+ lnC | .0304896 .0009509 32.06 0.000 .0286258 .0323533 lnL | -.9835998 .0006899 -1425.74 0.000 -.984952 -.9822476 lnE | .0652658 .0009439 69.14 0.000 .0634158 .0671159 lnM | .6729931 .0012158 553.53 0.000 .67061 .6753761 eco | .0610348 .0177048 3.45 0.001 .0263336 .095736 inno | .0173824 .0058224 2.99 0.003 .0059706 .0287943 eco_inno | .0080325 .0110815 0.72 0.469 -.0136872 .0297522 eco_lnE | .0276226 .004059 6.81 0.000 .019667 .0355781 eco_lnM | -.0214237 .0039927 -5.37 0.000 -.0292494 -.0135981 _Iyear_1998 | -.0317684 .0013978 -22.73 0.000 -.034508 -.0290287 _Iyear_1999 | -.0647261 .0027674 -23.39 0.000 -.0701501 -.0593021 _cons | 1.802112 .009304 193.69 0.000 1.783876 1.820348 -+ sigma_u | .38142386 sigma_e | .2173114 rho | .75494455 (fraction of variance due to u_i) -- F test that all u_i=0: F(48854, 97301) = 3.30 Prob F = 0. 3. Compute marginal effect of eco at sample mean . nlcom (_b[eco]+_b[inno]*.0880374+_b[eco_lnE]*.9256239+_b[eco_lnM]*4.281903) _nl_1: _b[eco]+_b[inno]*.0880374+_b[eco_lnE]*.9256239+_b[eco_lnM]*4.281903 -- lnLP | Coef. Std. Err. t P|t| [95% Conf. Interval] -+ _nl_1 | -.0036011 .008167 -0.44 0.659 -.0196084 .0124061 -- in fact i can find the mean of the variables ( step 1) and extimate the model (step 2) but i couldnt find the equivalent of step 3 (compute marginal effect of eco at sample mean). Can someone help me for this issue? Cheers! _ [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide
Re: [R] equivalent of stata command in R
From: saint-fi...@hotmail.com To: saint-fi...@hotmail.com Subject: RE: Date: Wed, 9 Jun 2010 09:53:20 + OK! sorry thats my fault, here the translations of the stata commands 1st step is to get the mean values of the variables, well that doesnt need explanation i guess, 2nd step is to estimate the model on panel data estimation method which is: mdl-plm(lnLP~lnC+lnL+lnM+lnE+Eco+Inno+Eco*Inno+Eco*lnM+Eco*lnE+year,data=newdata,model=within) and basically i need to get the marginal effect of variable Eco at the sample mean (step 3) but i am not that good in R so any additional help is wlcome! Thanks From: saint-fi...@hotmail.com To: r-help@r-project.org Subject: Date: Wed, 9 Jun 2010 09:45:16 + It helps if you translate the Stata commands. Not everybody is fluent in those. It would even help more if you would enlight us about the function you used to fit the model. Getting the marginal effects is not that hard at all, but how depends a bit on the function you used to estimate the model. You can try predict(your_model,type=terms,terms=the_term_you're_interested_in) For exact information, look at the respective predict function, eg if you use lme, do ?predict.lme Be aware of the fact that R normally choses the correct predict function without you having to specify it. predict() works for most model objects. Yet, depending on the model eacht predict function can have different options or different functionality. That information is in the help files of the specific function. Cheers Joris Dear all, I need to use R for one estimation, and i have readily available stata command, but i need also the R version of the same command. the estimation in stata is as following: 1. Compute mean values of relevant variables . sum inno lnE lnM Variable | ObsMeanStd. Dev. MinMax -+ inno |146574.0880374.2833503 0 1 lnE |146353.92562391.732912 -4.473922 10.51298 lnM |1462094.2819031.862192 -4.847253 13.71969 2. Estimate model . xi: xtreg lnLP lnC lnL lnE lnM eco inno eco_inno eco_lnE eco_lnM i.year, fe i(stno) i.year_Iyear_1997-1999(naturally coded; _Iyear_1997 omitted) Fixed-effects (within) regression Number of obs =146167 Group variable (i): stnoNumber of groups = 48855 R-sq: within = 0.9908 Obs per group: min = 1 between = 0.9122avg = 3.0 overall = 0.9635max = 3 F(11,97301)= 949024.29 corr(u_i, Xb) = 0.2166 Prob F =0. -- lnLP | Coef. Std. Err. tP|t| [95% Conf. Interval] -+ lnC | .0304896 .000950932.06 0.000 .0286258.0323533 lnL | -.9835998 .0006899 -1425.74 0.000 -.984952 -.9822476 lnE | .0652658 .000943969.14 0.000 .0634158.0671159 lnM | .6729931 .0012158 553.53 0.000 .67061.6753761 eco | .0610348 .0177048 3.45 0.001 .0263336 .095736 inno | .0173824 .0058224 2.99 0.003 .0059706.0287943 eco_inno | .0080325 .0110815 0.72 0.469-.0136872.0297522 eco_lnE | .0276226.004059 6.81 0.000 .019667.0355781 eco_lnM | -.0214237 .0039927-5.37 0.000-.0292494 -.0135981 _Iyear_1998 | -.0317684 .0013978 -22.73 0.000 -.034508 -.0290287 _Iyear_1999 | -.0647261 .0027674 -23.39 0.000-.0701501 -.0593021 _cons | 1.802112.009304 193.69 0.000 1.7838761.820348 -+ sigma_u | .38142386 sigma_e | .2173114 rho | .75494455 (fraction of variance due to u_i) -- F test that all u_i=0: F(48854, 97301) = 3.30Prob F = 0. 3. Compute marginal effect of eco at sample mean . nlcom (_b[eco]+_b[inno]*.0880374+_b[eco_lnE]*.9256239+_b[eco_lnM]*4.281903) _nl_1: _b[eco]+_b[inno]*.0880374+_b[eco_lnE]*.9256239+_b[eco_lnM]*4.281903 -- lnLP | Coef. Std. Err. tP|t| [95% Conf. Interval]
[R] Problem with library(SSPA)
Hello, I have the fellowing problem and I am thankful for any advice! Regards, Samuel source(http://bioconductor.org/biocLite.R;) BioC_mirror = http://www.bioconductor.org Change using chooseBioCmirror(). biocLite(SSPA) Using R version 2.11.0, biocinstall version 2.6.7. Installing Bioconductor version 2.6 packages: [1] SSPA Please wait... trying URL 'http://www.bioconductor.org/packages/2.6/bioc/bin/windows/contrib/2.11/SSPA_1.4.0.zip' Content type 'application/zip' length 305310 bytes (298 Kb) opened URL downloaded 298 Kb package 'SSPA' successfully unpacked and MD5 sums checked library(SSPA) Loading required package: qvalue Loading required package: tcltk Loading Tcl/Tk interface ... done Error : .onAttach failed in attachNamespace() for 'SSPA', details: call: fun(...) error: could not find function addVigs2WinMenu Error: package/namespace load failed for 'SSPA' sessionInfo() R version 2.11.0 (2010-04-22) i386-pc-mingw32 locale: [1] LC_COLLATE=English_United Kingdom.1252 LC_CTYPE=English_United Kingdom.1252 LC_MONETARY=English_United Kingdom.1252 [4] LC_NUMERIC=C LC_TIME=English_United Kingdom.1252 attached base packages: [1] tcltk stats graphics grDevices utils datasets methods base other attached packages: [1] qvalue_1.22.0 loaded via a namespace (and not attached): [1] limma_3.4.3 SSPA_1.4.0 tools_2.11.0 ## [[alternative HTML version deleted]] __ 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 commented, minimal, self-contained, reproducible code.
[R] Read in dataset without saving it
A simple question - I have a small dataset to read in and want to copy and paste part from Excel and paste it into an R script file without creating more files saving it as a .txt/.csv and then reading that in. I want to read in 3 columns e.g. 1 2.5 3.4 1 2.3 3.1 1 2.6 3.9 2 2.9 2.8 2 2.6 2.9 2 2.7 2.9 3 2.3 3.3 3 2.4 3.0 3 2.7 3.2 I thought I could use scan() but don't know how to extend it to multiple columns? I thought about using colwise (plyr) but think I am making this more complicated than it probably should be! Is there an easy way to do this? Any ideas gratefully received, Paul -- View this message in context: http://r.789695.n4.nabble.com/Read-in-dataset-without-saving-it-tp2248495p2248495.html Sent from the R help mailing list archive at Nabble.com. __ 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 commented, minimal, self-contained, reproducible code.
Re: [R] Please help me
Dear Xionqing, It's still difficult to say without the data, but I guess the error message reads System computation is singular, meaning you just have too many variables or some variables are near-aliases of eachother. I did not ask to read the posting guide to be difficult. Without some reproducible code and detailed information on the data, it's impossible to say what is the problem exactly. Cheers Joris On Wed, Jun 9, 2010 at 2:47 AM, Xiongqing Zhang xqzhan...@yahoo.com wrote: Dear Joris, Thank for your reply. Firstly, I introduced one dummy variable (eg: u=0, the first group; u=1, the second group) to the model, and I got the results (parameter estimators and AIC value). #zero inflated negative binomial model library(pscl) dat=read.csv(data.csv,header=T) zinb - zeroinfl(y ~x1+x2+x3+x4+x5+u | x1+x2+x3+x4+x5+u, data = dat, link= logit, dist = negbin) summary(zinb) But the results are not satisfied to me. So I decided to introduce two dummy variables (u1,u2) to the model, and then I could not get the results. dat=read.csv(data.csv,header=T) zinb - zeroinfl(y ~x1+x2+x3+x4+x5+u1+u2 | x1+x2+x3+x4+x5+u1+u2, data = dat, link= logit, dist = negbin) summary(zinb) And the error message is error in solve.default(as.matrix(fit$hessian)) : System computation is unsigular moreover: Warning message: In glm.fit(Z, as.integer(Y0), weights = weights, family = binomial(link = linkstr), : algorithm did not converge Again, many thanks for you. Sincerely, Xiongqing --- On *Tue, 6/8/10, Joris Meys jorism...@gmail.com* wrote: From: Joris Meys jorism...@gmail.com Subject: Re: [R] Please help me To: Xiongqing Zhang xqzhan...@yahoo.com Cc: r-help@r-project.org Date: Tuesday, June 8, 2010, 11:22 AM First, read the posting guides. Then, supply us with a bit more information, like the package you used, example code that reproduces the error, information about the data, the complete error message, the traceback (use the function traceback() right after you got the error). Otherwise we ain't going to be able to help you. Cheers Joris On Tue, Jun 8, 2010 at 9:42 AM, Xiongqing Zhang xqzhan...@yahoo.comhttp://cn.mc453.mail.yahoo.com/mc/compose?to=xqzhan...@yahoo.com wrote: Dear Mr. or Ms., I used the R-software to run the zero-inflatoin negative binomial model (zeroinfl()) . Firstly, I introduced one dummy variable to the model as an independent variable, and I got the estimators of parameters. But the results are not satisfied to me. So I introduced three dummy variables to the model. but I could not get the results. And the error message is solve.default(as.matrix(fit$gaussian)) . I do not know the reasons fully. And I want to know what method was used to estimate the parameters when I called the function zeroinfl() . I will be very appreciate if you can help me. Thank you. Best regards, Sincerely, Xiongqing Zhang [[alternative HTML version deleted]] __ R-help@r-project.orghttp://cn.mc453.mail.yahoo.com/mc/compose?to=r-h...@r-project.orgmailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Joris Meys Statistical consultant Ghent University Faculty of Bioscience Engineering Department of Applied mathematics, biometrics and process control tel : +32 9 264 59 87 joris.m...@ugent.behttp://cn.mc453.mail.yahoo.com/mc/compose?to=joris.m...@ugent.be --- Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php -- Joris Meys Statistical consultant Ghent University Faculty of Bioscience Engineering Department of Applied mathematics, biometrics and process control tel : +32 9 264 59 87 joris.m...@ugent.be --- Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php [[alternative HTML version deleted]] __ 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 commented, minimal, self-contained, reproducible code.
Re: [R] ordisurf (pkg vegan) gives implausible result
Ordisurf uses a gam model to fit the surface (and more exactly, in your case a thin plate regression spline). Standard these ts splines try to reduce the dimensionality of your model as much as possible. Hence in your case they fit indeed a linear plane through the space, which is supposed to be the best fit. If you want an exact fit of your data, you shouldn't use a model. To see what goes on, you can try following right after the ordisurf command : lK - cut2(K,g=5,onlycuts=T) gen - (K-min(K)+0.1)/(max(K)+0.2-min(K)) leg - (lK-min(K)+0.1)/(max(K)+0.2-min(K)) colgen - rgb(0,gen,0) points(sample.mds$points, pch=19,col=colgen) colleg - rgb(0,leg,0) legend(topleft,legend=lK,col=colleg,horiz=T,pch=19) This plots the values in color coding, so you can try to judge the fit. Also look at the object from ordisurf itself: ordi.object - ordisurf(sample.mds, edaphic$K, xlab=PC 1, ylab=PC 2, main=K) str(ordi.object) This should contain the information on the gam fit. Cheers Joris On Wed, Jun 9, 2010 at 5:33 AM, Matt Bakker matt.g.bak...@gmail.com wrote: I'm having trouble with the ordisurf function in the vegan package. I have created an ordination plot (cmdscale) of 60 samples based on Bray-Curtis dissimilarities, and would like to overlay various soil edaphic characteristics as possible clues to the clustering I observe in my plot. However, I find that ordisurf creates a surface on the plot that is a perfect, even gradient - and doesn't match my data. An example of this output is attached (as .ps file), while these are the data for the environmental variable of interest: edaphic$K [1] 28 61 48 29 28 26 45 28 34 33 55 62 44 51 60 68 51 31 54 32 58 50 37 35 35 34 52 29 53 24 37 50 62 51 [35] 28 39 47 41 49 83 33 50 55 71 59 50 57 47 46 49 43 30 56 23 49 35 31 27 38 52 The contour lines suggest that there are only two values below 32, when in fact there are 11. Any ideas? Thanks! bc - read.table(braycurtis_noheader.dist,header=F) sample.mds - cmdscale(bc) edaphic - read.table(edaphic.txt, header=T) library(vegan) This is vegan 1.17-2 ordisurf(sample.mds, edaphic$K, xlab=PC 1, ylab=PC 2, main=K) Loading required package: mgcv This is mgcv 1.6-1. For overview type `help(mgcv-package)'. Family: gaussian Link function: identity Formula: y ~ s(x1, x2, k = knots) Estimated degrees of freedom: 2 total = 3 GCV score: 140.9051 -- Matthew Bakker Ph.D. Candidate Department of Plant Pathology University of Minnesota 495 Borlaug Hall 1991 Upper Buford Circle Saint Paul, MN 55108 USA 612-624-2253 matt.g.bak...@gmail.com http://plpa.cfans.umn.edu/Matt_Bakker.html __ 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 commented, minimal, self-contained, reproducible code. -- Joris Meys Statistical consultant Ghent University Faculty of Bioscience Engineering Department of Applied mathematics, biometrics and process control tel : +32 9 264 59 87 joris.m...@ugent.be --- Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php __ 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 commented, minimal, self-contained, reproducible code.
[R] minor tick marks
Hi ! I need a plot for data extending over several orders of magnitude on the y axis. The following command generates a nice looking semi-log plot for my data: plot(x,y,log=y,type=l,lty=3, ylim=c(0.01,2),yaxp=c(0.01,1,1),las=1) I would appreciate having also minor tick marks in-between the 3 major ticks obtained with the above command. The minor.tick function in library Hmisc gives an error when applied to log axes. Any solution ? Stéphane _ Stéphane Adamowicz INRA, unité PSH domaine St Paul, site agroparc 84914 Avignon, cedex 9 France stephane.adamow...@avignon.inra.fr tel. +33 (0)4 32 72 24 35 fax. +33 (0)4 32 72 24 32 do not dial 0 when out of France web PSH : http://www.avignon.inra.fr/psh web INRA : http://www.inra.fr/ _ [[alternative HTML version deleted]] __ 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 commented, minimal, self-contained, reproducible code.
[R] Problem using Rmpi
Hi Thanks to the help from Uwe Ligges I could update Rmpi package. Now R can load the package but it still does not work. Now the problem comes when trying to use the first Rmpi command in a basic tutorial: library(Rmpi) mpi.spawn.Rslaves() Error en mpi.spawn.Rslaves() : You cannot use MPI_Comm_spawn API Seaching in the list I have found references to this problem but not the solution. More info about R and MPICH installation in my system (Ubuntu Hardy Heron in a dual AMD Athlon PC) can be found in http://ubuntuone.com/p/6Wr/ Thanks in advance -- --- Francisco Pastor Meteorology department Fundación CEAM p...@ceam.es http://www.ceam.es/ceamet - http://www.ceam.es Parque Tecnologico, C/ Charles R. Darwin, 14 46980 PATERNA (Valencia), Spain Tlf. 96 131 82 27 - Fax. 96 131 81 90 --- Usuario Linux registrado: 363952 __ 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 commented, minimal, self-contained, reproducible code.
Re: [R] minor tick marks
Hello, Perhaps something like: axis( 2, 0:10/10, las = 1, tcl = -.2 ) Romain Le 09/06/10 11:08, Stéphane Adamowicz a écrit : Hi ! I need a plot for data extending over several orders of magnitude on the y axis. The following command generates a nice looking semi-log plot for my data: plot(x,y,log=y,type=l,lty=3, ylim=c(0.01,2),yaxp=c(0.01,1,1),las=1) I would appreciate having also minor tick marks in-between the 3 major ticks obtained with the above command. The minor.tick function in library Hmisc gives an error when applied to log axes. Any solution ? Stéphane _ Stéphane Adamowicz INRA, unité PSH domaine St Paul, site agroparc 84914 Avignon, cedex 9 France stephane.adamow...@avignon.inra.fr tel. +33 (0)4 32 72 24 35 fax. +33 (0)4 32 72 24 32 do not dial 0 when out of France web PSH : http://www.avignon.inra.fr/psh web INRA : http://www.inra.fr/ -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://bit.ly/98Uf7u : Rcpp 0.8.1 |- http://bit.ly/c6YnCi : graph gallery collage `- http://bit.ly/bZ7ltC : inline 0.3.5 __ 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 commented, minimal, self-contained, reproducible code.
[R] dealing with heteroscedasticity in lmer: problem with the method weights
Dear lmer users, The experiment includes 15 groups of (3 males and 1 female). The female is characterized by its quality Q1 and Q2. Each male of a group is characterized by the number of MatingAttempts (with Poisson distribution). I want to examine if male mating attempts depend on female quality. I can see from graphic exploration that the within-group heterogeneity of male attempts increases with female quality Q1. When including the method weights in the function lmer, I get the message that variables' length varies and the model does not run. lmer(MatingAttempts~Q1+Q2+(1|Group),data=file,family=poisson,na.action=na.omit, REML=FALSE, weights=varExp(form=~Q1)) If I run the same model (fixed effects and random effects) with lme, it works properly, which shows that there is no problem with data structure. lme(MatingAttempts~Q1+Q2,random=~1|Group,data=file,na.action=na.omit, method=ML, weights=varExp(form=~Q1)) I saw on the forum that lmer had problems in taking into account variance heterogeneity. Yet, the messages were old and there are maybe new solutions. How can I correct the analyses for this problem of heteroscedasticity? Should I normalise the within group variance before implementing the model? And deal with the variance (as a new variable to explain) in another model? Is there another way to solve this problem? Thank you in advance for your help Doris Gomez [[alternative HTML version deleted]] __ 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 commented, minimal, self-contained, reproducible code.
Re: [R] Read in dataset without saving it
See ?textConnection, eg test -1 2.5 3.4 1 2.3 3.1 1 2.6 3.9 2 2.9 2.8 2 2.6 2.9 2 2.7 2.9 3 2.3 3.3 3 2.4 3.0 3 2.7 3.2 x - textConnection(test) read.table(x) close(x) On Wed, Jun 9, 2010 at 10:38 AM, Paul Chatfield p.s.chatfi...@reading.ac.uk wrote: A simple question - I have a small dataset to read in and want to copy and paste part from Excel and paste it into an R script file without creating more files saving it as a .txt/.csv and then reading that in. I want to read in 3 columns e.g. 1 2.5 3.4 1 2.3 3.1 1 2.6 3.9 2 2.9 2.8 2 2.6 2.9 2 2.7 2.9 3 2.3 3.3 3 2.4 3.0 3 2.7 3.2 I thought I could use scan() but don't know how to extend it to multiple columns? I thought about using colwise (plyr) but think I am making this more complicated than it probably should be! Is there an easy way to do this? Any ideas gratefully received, Paul -- View this message in context: http://r.789695.n4.nabble.com/Read-in-dataset-without-saving-it-tp2248495p2248495.html Sent from the R help mailing list archive at Nabble.com. __ 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 commented, minimal, self-contained, reproducible code. -- Joris Meys Statistical consultant Ghent University Faculty of Bioscience Engineering Department of Applied mathematics, biometrics and process control tel : +32 9 264 59 87 joris.m...@ugent.be --- Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php __ 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 commented, minimal, self-contained, reproducible code.
[R] Sorting Association Rules on 2 criteria
I'm using library(arules) Once rules have been created one can inspect sort them. Here is an example to sort on support. I want to sort on support AND THEN confidence - Is this possible ? inspect (SORT(rules, by = support)) Regards __ 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 commented, minimal, self-contained, reproducible code.
Re: [R] Extracting Elements By Date
Try this and next time provide reproducible code and data as per posting guide (see last line of every message). First we create a sample data frame, DF. Then we use the zoo time series package to read it in and convert it from long form, DF, to wide form, z, with one column per id. Then we use split to split it into two day groups noting that %/% signifies integer division. Since we have 4 successive days here this gives two groups of two days each. See ?read.zoo and the three zoo vignettes (pdf documents) that come with the zoo package. Also see ?split # sample data DF - data.frame(Date = as.Date(2000-1-1) + 0:3, id = A, value = 1:4) DF - rbind(DF, transform(DF, id = B)) DF Date id value 1 2000-01-01 A 1 2 2000-01-02 A 2 3 2000-01-03 A 3 4 2000-01-04 A 4 5 2000-01-01 B 1 6 2000-01-02 B 2 7 2000-01-03 B 3 8 2000-01-04 B 4 library(zoo) # need devel version of read.zoo source(http://r-forge.r-project.org/scm/viewvc.php/*checkout*/pkg/zoo/R/read.zoo.R?revision=719root=zoo;) z - read.zoo(DF, split = id) z A B 2000-01-01 1 1 2000-01-02 2 2 2000-01-03 3 3 2000-01-04 4 4 split(z, as.numeric(time(z) - start(z)) %/% 2) $`0` A B 2000-01-01 1 1 2000-01-02 2 2 $`1` A B 2000-01-03 3 3 2000-01-04 4 4 On Tue, Jun 8, 2010 at 9:49 PM, Jeff08 jefferyd...@gmail.com wrote: Dear R Gurus, Thanks for any help in advance! Date.frame: Returns.names X id ticker date_ adjClose totret RankStk 258060 258060 13645T10 CP 2001-06-29 18.125 1877.758 My data frame is in the above format. I would like to filter by period, per id (every 125 days) each consisting of 250 days, I.e. 1-250, 126-375, etc. One important thing to note is that not all ID's have the same number of dates. x-unique(Returns.names$date_) gives me the ordered list of all the dates, so for each period i want it would be x[((n-1)*125+1):((n+1)*125)] when i tried to filter for just 1 period, it worked fine, but alas, I do not know how to work around the problem that you cannot assign dynamic variables in loops (say I named the variable for the extracted dates Returns.period, it would get overwritten every iteration of the loop, and I cant name something Returns.n, where n is the index for the loop) Thus, I tried to adjust by dynamically assigning each period to a column. However, I get the error: object 'Returns.period1' not found. And R is not like Java where you can simply declare a variable by typing say Returns.period1. I do not know how to create a flexible empty matrix that would allow this code to work. If anyone knows how to do this without a loop, that would be even better! ##Filtering by Period n-1 while(n=19) { Returns.period-lapply(((n-1)*125+1):((n+1)*125), function (i) which(Returns.filter$date_==x[i])) Returns.period-unlist(Returns.period) Returns.period1[n,1:(length(Returns.period))]-Returns.filter[Returns.period,] n-n+1 } -- View this message in context: http://r.789695.n4.nabble.com/Extracting-Elements-By-Date-tp2248227p2248227.html Sent from the R help mailing list archive at Nabble.com. __ 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 commented, minimal, self-contained, reproducible code. __ 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 commented, minimal, self-contained, reproducible code.
Re: [R] Read in dataset without saving it
Hi r-help-boun...@r-project.org napsal dne 09.06.2010 12:44:33: See ?textConnection, eg test -1 2.5 3.4 1 2.3 3.1 1 2.6 3.9 2 2.9 2.8 2 2.6 2.9 2 2.7 2.9 3 2.3 3.3 3 2.4 3.0 3 2.7 3.2 x - textConnection(test) read.table(x) close(x) On Wed, Jun 9, 2010 at 10:38 AM, Paul Chatfield p.s.chatfi...@reading.ac.uk wrote: A simple question - I have a small dataset to read in and want to copy and paste part from Excel and paste it into an R script file without creating more files saving it as a .txt/.csv and then reading that in. I want to In Excel select what you want to copy press Ctrl C In R use read.delim(clipboard) or read.table(clipboard) depending whether you selected or did not selected some header. Regards Petr read in 3 columns e.g. 1 2.5 3.4 1 2.3 3.1 1 2.6 3.9 2 2.9 2.8 2 2.6 2.9 2 2.7 2.9 3 2.3 3.3 3 2.4 3.0 3 2.7 3.2 I thought I could use scan() but don't know how to extend it to multiple columns? I thought about using colwise (plyr) but think I am making this more complicated than it probably should be! Is there an easy way to do this? Any ideas gratefully received, Paul -- View this message in context: http://r.789695.n4.nabble.com/Read-in-dataset- without-saving-it-tp2248495p2248495.html Sent from the R help mailing list archive at Nabble.com. __ 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 commented, minimal, self-contained, reproducible code. -- Joris Meys Statistical consultant Ghent University Faculty of Bioscience Engineering Department of Applied mathematics, biometrics and process control tel : +32 9 264 59 87 joris.m...@ugent.be --- Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php __ 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 commented, minimal, self-contained, reproducible code. __ 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 commented, minimal, self-contained, reproducible code.
Re: [R] Read in dataset without saving it
See: http://rwiki.sciviews.org/doku.php?id=tips:data-io:ms_windowss=excel On Wed, Jun 9, 2010 at 4:38 AM, Paul Chatfield p.s.chatfi...@reading.ac.uk wrote: A simple question - I have a small dataset to read in and want to copy and paste part from Excel and paste it into an R script file without creating more files saving it as a .txt/.csv and then reading that in. I want to read in 3 columns e.g. 1 2.5 3.4 1 2.3 3.1 1 2.6 3.9 2 2.9 2.8 2 2.6 2.9 2 2.7 2.9 3 2.3 3.3 3 2.4 3.0 3 2.7 3.2 I thought I could use scan() but don't know how to extend it to multiple columns? I thought about using colwise (plyr) but think I am making this more complicated than it probably should be! Is there an easy way to do this? Any ideas gratefully received, Paul -- View this message in context: http://r.789695.n4.nabble.com/Read-in-dataset-without-saving-it-tp2248495p2248495.html Sent from the R help mailing list archive at Nabble.com. __ 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 commented, minimal, self-contained, reproducible code. __ 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 commented, minimal, self-contained, reproducible code.
Re: [R] Efficiency question
On Tue, Jun 8, 2010 at 11:53 PM, Worik R wor...@gmail.com wrote: Given the following snippet m.nf.xts - xts(rep(0, length(index(m.xts))), order.by=index(m.xts)) Does R know to cache the index(m.xts) or is it more efficient to say... m.i - index(m.xts) m.nf.xts - xts(rep(0, length(m.i)), order.by=index(m.i)) this is one call less to a function, and hence more efficient. I suppose it has to be order.by=m.i Btw, How should R know what to cache? If it would cache all calculations, you'd be out of memory in no time. If you have more questions like this, you can test it by yourself, eg : x - sample(rnorm(100)) id - index(x) # is in this case equivalent to 1:100 system.time(replicate(10^5,{rep(0,length(index(x)))[index(x)]})) user system elapsed 7.610.097.76 system.time(replicate(10^5,{rep(0,length(id))[id]})) user system elapsed 1.490.061.58 Cheers Joris ? cheers Worik [[alternative HTML version deleted]] __ 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 commented, minimal, self-contained, reproducible code. -- Joris Meys Statistical consultant Ghent University Faculty of Bioscience Engineering Department of Applied mathematics, biometrics and process control tel : +32 9 264 59 87 joris.m...@ugent.be --- Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php __ 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 commented, minimal, self-contained, reproducible code.
[R] Rglpk
Hi list, in the Rglpk_solve_LP function (::Rglpk), on line 26, the function calls a function as.glp_bounds() that i cannot access. i'm trying to alter the Rglpk_solve_LP function to add a line to retrieve column/row dual values. everytime i change the slightest line of code inside Rglpk_solve_LP() [to even add a print] i get a ': could not find function as.glp_bounds' What's the catch here ? Best, __ 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 commented, minimal, self-contained, reproducible code.
[R] bootpred for multinomial
I applied bootpred for multinomial logistic reg. (with nnet package). I used same as theta.fit and theta.predict of R for my data. but give me error. Can I do this with response vriable;7 levels predictor variables:5 (1 classifier, 4 continuous)? Thanks alot Azam [[alternative HTML version deleted]] __ 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 commented, minimal, self-contained, reproducible code.
[R] strange issue with which on seq
Dear R community, I am puzzled by the following lines: v - seq(-0.5,0.5,by=0.1) v [1] -0.5 -0.4 -0.3 -0.2 -0.1 0.0 0.1 0.2 0.3 0.4 0.5 which(v == -0.4) [1] 2 which(v == 0) [1] 6 which(v == 0.1) integer(0) which(v == 0.2) integer(0) which(v == 0.3) integer(0) which(v == 0.4) [1] 10 which(v == 0.5) [1] 11 Why which can only match some of the values in v? Are the numbers generated by seq not exact fractional numbers? Please, help me to understand this. J Dr James Foadi PhD Membrane Protein Laboratory (MPL) Diamond Light Source Ltd Diamond House Harewell Science and Innovation Campus Chilton, Didcot Oxfordshire OX11 0DE Email: james.fo...@diamond.ac.uk Alt Email: j.fo...@imperial.ac.uk -- This e-mail and any attachments may contain confidential...{{dropped:8}} __ 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 commented, minimal, self-contained, reproducible code.
[R] Odp: strange issue with which on seq
Hi r-help-boun...@r-project.org napsal dne 09.06.2010 13:16:40: Dear R community, I am puzzled by the following lines: v - seq(-0.5,0.5,by=0.1) v [1] -0.5 -0.4 -0.3 -0.2 -0.1 0.0 0.1 0.2 0.3 0.4 0.5 which(v == -0.4) [1] 2 which(v == 0) [1] 6 which(v == 0.1) integer(0) which(v == 0.2) integer(0) which(v == 0.3) integer(0) which(v == 0.4) [1] 10 which(v == 0.5) [1] 11 Why which can only match some of the values in v? Are the numbers generated by seq not exact fractional numbers? Please, help me to understand this. Well FAQ 7.31 was not here some time. Computing in binary results in finite precision of fractional numbers. v - seq(-0.5,0.5,by=0.1) v[7]-0.1 [1] 8.326673e-17 Regards Petr J Dr James Foadi PhD Membrane Protein Laboratory (MPL) Diamond Light Source Ltd Diamond House Harewell Science and Innovation Campus Chilton, Didcot Oxfordshire OX11 0DE Email: james.fo...@diamond.ac.uk Alt Email: j.fo...@imperial.ac.uk -- This e-mail and any attachments may contain confidential...{{dropped:8}} __ 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 commented, minimal, self-contained, reproducible code. __ 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 commented, minimal, self-contained, reproducible code.
Re: [R] specifying plot symbol sizes in qplot or ggplot2
Have a look at ?scale_size_manual() HTH, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek team Biometrie Kwaliteitszorg Gaverstraat 4 9500 Geraardsbergen Belgium Research Institute for Nature and Forest team Biometrics Quality Assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 thierry.onkel...@inbo.be www.inbo.be To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher The plural of anecdote is not data. ~ Roger Brinner The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data. ~ John Tukey -Oorspronkelijk bericht- Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Namens cfriedl Verzonden: woensdag 9 juni 2010 3:22 Aan: r-help@r-project.org Onderwerp: [R] specifying plot symbol sizes in qplot or ggplot2 Hi. first things first ... thanks for ggplot2. Now my question. I'm using qplot to generate a plot as follows where X,Y,Z, A are columns in a dataframe. qplot(X, Y, data=XYDATA, color=Z, geom=c(point), size=A) This works as expected. Factor A has three levels so there are three sizes of the point plot symbol. I understand that the factor levels are mapped to symbol sizes. However the sizes are too small for my liking. Is there any way I can specify the range of plot symbol sizes that factor A levels are mapped to? -- View this message in context: http://r.789695.n4.nabble.com/specifying-plot-symbol-sizes-in- qplot-or-ggplot2-tp2248217p2248217.html Sent from the R help mailing list archive at Nabble.com. __ 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 commented, minimal, self-contained, reproducible code. Druk dit bericht a.u.b. niet onnodig af. Please do not print this message unnecessarily. Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is door een geldig ondertekend document. The views expressed in this message and any annex are purely those of the writer and may not be regarded as stating an official position of INBO, as long as the message is not confirmed by a duly signed document. __ 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 commented, minimal, self-contained, reproducible code.
[R] Help needed on switch function
Hi all, Here I am trying to implement the switch() function to choose value of a variable depending on the value of an input variable : temp1 - 1 temp1.name - switch(temp1, 1 == aa, 2 == bb, 3 == cc, 4 == dd, 5 == ee) Goal is if temp1 equals to 1, then value of temp1.name would be aa. However I am getting following answer : temp1 - 1 temp1.name - switch(temp1, + 1 == aa, + 2 == bb, + 3 == cc, + 4 == dd, + 5 == ee) temp1.name [1] FALSE Can anyone please point me where I am doing wrong? Thanks, [[alternative HTML version deleted]] __ 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 commented, minimal, self-contained, reproducible code.
Re: [R] equivalent of stata command in R
Thanx for your response, yeah, i know i didnst specified the indexes when i wrote the 2nd mail, in fact in the 1st mail i wrote already that i dont have problem with the estimation of the model... thats the reason why i didnt write in fact since the issue is not to estimate the model but to get the marginal effect, anyway, i figured out that predict(), doesnt work for panel data... and well, my problem is that contrary to your guess, i couldnt figure out the rest of the calculations... since i am not that experienced in R. one last help of yours would be quite helpful to get rid of this silly problem! Thanx again... Date: Wed, 9 Jun 2010 12:40:42 +0200 Subject: Re: [R] equivalent of stata command in Râ From: jorism...@gmail.com To: saint-fi...@hotmail.com CC: r-help@r-project.org plm does not have a predict function, so forget my former mail. To get to the coefficients, you just : coef(mdl) The rest of the calculations you can figure out I guess. I'm also not sure if you're doing what you think you're doing. You never specified the index stno in your pml call. Read the help files again. And while you're at it, read the posting guide for the list as well: http://www.R-project.org/posting-guide.html Cheers Joris On Wed, Jun 9, 2010 at 11:54 AM, mike mick saint-fi...@hotmail.com wrote: From: saint-fi...@hotmail.com To: saint-fi...@hotmail.com Subject: RE: Date: Wed, 9 Jun 2010 09:53:20 + OK! sorry thats my fault, here the translations of the stata commands 1st step is to get the mean values of the variables, well that doesnt need explanation i guess, 2nd step is to estimate the model on panel data estimation method which is: mdl-plm(lnLP~lnC+lnL+lnM+lnE+Eco+Inno+Eco*Inno+Eco*lnM+Eco*lnE+year,data=newdata,model=within) and basically i need to get the marginal effect of variable Eco at the sample mean (step 3) but i am not that good in R so any additional help is wlcome! Thanks From: saint-fi...@hotmail.com To: r-help@r-project.org Subject: Date: Wed, 9 Jun 2010 09:45:16 + It helps if you translate the Stata commands. Not everybody is fluent in those. It would even help more if you would enlight us about the function you used to fit the model. Getting the marginal effects is not that hard at all, but how depends a bit on the function you used to estimate the model. You can try predict(your_model,type=terms,terms=the_term_you're_interested_in) For exact information, look at the respective predict function, eg if you use lme, do ?predict.lme Be aware of the fact that R normally choses the correct predict function without you having to specify it. predict() works for most model objects. Yet, depending on the model eacht predict function can have different options or different functionality. That information is in the help files of the specific function. Cheers Joris Dear all, I need to use R for one estimation, and i have readily available stata command, but i need also the R version of the same command. the estimation in stata is as following: 1. Compute mean values of relevant variables . sum inno lnE lnM Variable | ObsMeanStd. Dev. MinMax -+ inno |146574.0880374.2833503 0 1 lnE |146353.92562391.732912 -4.473922 10.51298 lnM |1462094.2819031.862192 -4.847253 13.71969 2. Estimate model . xi: xtreg lnLP lnC lnL lnE lnM eco inno eco_inno eco_lnE eco_lnM i.year, fe i(stno) i.year_Iyear_1997-1999(naturally coded; _Iyear_1997 omitted) Fixed-effects (within) regression Number of obs = 146167 Group variable (i): stnoNumber of groups = 48855 R-sq: within = 0.9908 Obs per group: min = 1 between = 0.9122avg = 3.0 overall = 0.9635max = 3 F(11,97301)= 949024.29 corr(u_i, Xb) = 0.2166 Prob F = 0. -- lnLP | Coef. Std. Err. tP|t| [95% Conf. Interval] -+ lnC | .0304896 .000950932.06 0.000 .0286258 .0323533 lnL | -.9835998 .0006899 -1425.74 0.000 -.984952 -.9822476 lnE | .0652658 .000943969.14 0.000 .0634158 .0671159 lnM | .6729931 .0012158
[R] Testing for differences in amplitude and phase
Dear R-helpers, I have time series data from 16 subjects and 2 treatment groups. The seasonal variation can be best described by two harmonics, I called the frequencies omega and omega2. I now want to test whether (1) the seasonal pattern differs between the treatments (some kind of overall test). If this is the case, (2) I want to conduct tests to find out whether the amplitude of the fist harmonic, the amplitude of the second harmonic, the phase of the first harmonic and the phase of the second harmonic differs between the treatment groups. My attempt was to create a lme containing the two oscillations and the treatment group: omegaDay=omega*Day # there is probably a more elegant solution omega2Day=omega2*Day m=lme(y~(cos(omegaDay)+sin(omegaDay)+cos(omega2Day)+sin(omega2Day))*treatment, random=~1|subject) summary(m) The summary table tells me that the respective elements are significant (except for cos(omegaDay):treatmentTRUE). I know how to calculate the amplitudes and phases for both treatment groups from the model estimates, but how do I know if they are significantly different? Thanks to anyone who takes the time to help me with this problem! Karin _ Hotmail: Vertrauenswürdige E-Mails dank leistungsstarkem SPAM-Schutz. https://signup.live.com/signup.aspx?id=60969 [[alternative HTML version deleted]] __ 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 commented, minimal, self-contained, reproducible code.
Re: [R] equivalent of stata command in R
plm does not have a predict function, so forget my former mail. To get to the coefficients, you just : coef(mdl) The rest of the calculations you can figure out I guess. I'm also not sure if you're doing what you think you're doing. You never specified the index stno in your pml call. Read the help files again. And while you're at it, read the posting guide for the list as well: http://www.R-project.org/posting-guide.html Cheers Joris On Wed, Jun 9, 2010 at 11:54 AM, mike mick saint-fi...@hotmail.com wrote: From: saint-fi...@hotmail.com To: saint-fi...@hotmail.com Subject: RE: Date: Wed, 9 Jun 2010 09:53:20 + OK! sorry thats my fault, here the translations of the stata commands 1st step is to get the mean values of the variables, well that doesnt need explanation i guess, 2nd step is to estimate the model on panel data estimation method which is: mdl-plm(lnLP~lnC+lnL+lnM+lnE+Eco+Inno+Eco*Inno+Eco*lnM+Eco*lnE+year,data=newdata,model=within) and basically i need to get the marginal effect of variable Eco at the sample mean (step 3) but i am not that good in R so any additional help is wlcome! Thanks From: saint-fi...@hotmail.com To: r-help@r-project.org Subject: Date: Wed, 9 Jun 2010 09:45:16 + It helps if you translate the Stata commands. Not everybody is fluent in those. It would even help more if you would enlight us about the function you used to fit the model. Getting the marginal effects is not that hard at all, but how depends a bit on the function you used to estimate the model. You can try predict(your_model,type=terms,terms=the_term_you're_interested_in) For exact information, look at the respective predict function, eg if you use lme, do ?predict.lme Be aware of the fact that R normally choses the correct predict function without you having to specify it. predict() works for most model objects. Yet, depending on the model eacht predict function can have different options or different functionality. That information is in the help files of the specific function. Cheers Joris Dear all, I need to use R for one estimation, and i have readily available stata command, but i need also the R version of the same command. the estimation in stata is as following: 1. Compute mean values of relevant variables . sum inno lnE lnM Variable | Obs Mean Std. Dev. Min Max -+ inno | 146574 .0880374 .2833503 0 1 lnE | 146353 .9256239 1.732912 -4.473922 10.51298 lnM | 146209 4.281903 1.862192 -4.847253 13.71969 2. Estimate model . xi: xtreg lnLP lnC lnL lnE lnM eco inno eco_inno eco_lnE eco_lnM i.year, fe i(stno) i.year _Iyear_1997-1999 (naturally coded; _Iyear_1997 omitted) Fixed-effects (within) regression Number of obs = 146167 Group variable (i): stno Number of groups = 48855 R-sq: within = 0.9908 Obs per group: min = 1 between = 0.9122 avg = 3.0 overall = 0.9635 max = 3 F(11,97301) = 949024.29 corr(u_i, Xb) = 0.2166 Prob F = 0. -- lnLP | Coef. Std. Err. t P|t| [95% Conf. Interval] -+ lnC | .0304896 .0009509 32.06 0.000 .0286258 .0323533 lnL | -.9835998 .0006899 -1425.74 0.000 -.984952 -.9822476 lnE | .0652658 .0009439 69.14 0.000 .0634158 .0671159 lnM | .6729931 .0012158 553.53 0.000 .67061 .6753761 eco | .0610348 .0177048 3.45 0.001 .0263336 .095736 inno | .0173824 .0058224 2.99 0.003 .0059706 .0287943 eco_inno | .0080325 .0110815 0.72 0.469 -.0136872 .0297522 eco_lnE | .0276226 .004059 6.81 0.000 .019667 .0355781 eco_lnM | -.0214237 .0039927 -5.37 0.000 -.0292494 -.0135981 _Iyear_1998 | -.0317684 .0013978 -22.73 0.000 -.034508 -.0290287 _Iyear_1999 | -.0647261 .0027674 -23.39 0.000 -.0701501 -.0593021 _cons | 1.802112 .009304 193.69 0.000 1.783876 1.820348 -+ sigma_u | .38142386 sigma_e | .2173114 rho | .75494455 (fraction of variance due to u_i) -- F test that all
[R] RMySQL package on 64bit R for Windows
Hi, I have installed 64bit R version 2.11.1 on 64bit Vista system and I have a problem with RMySQL package. I have installed 64bit verion of MySQL (5.1.47) and set MYSQL_HOME. Installation of package looks fine : install.packages(RMySQL_0.7-4.zip) inferring 'repos = NULL' from the file name package 'RMySQL' successfully unpacked and MD5 sums checked but whet I try to load it I've got following error: library(RMySQL) Error: package 'RMySQL' is not installed for 'arch=x64' In addition: Warning message: package 'RMySQL' was built under R version 2.12.0 I have tried also installing package from source using RTools but it's also failed. If somebody succesfully install RMySQL package on 64bit R for Windows? I'll be thankful for any help. __ 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 commented, minimal, self-contained, reproducible code.
[R] Taylor Diagram
Dear R users, I need to learn plotting Taylor diagram. I dowloaded the plotrix that includes taylor.diagram but I dont know how to study with real datasets. Anyone help me? Tufan [[alternative HTML version deleted]] __ 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 commented, minimal, self-contained, reproducible code.
Re: [R] Help needed on switch function
R is confused about the type in the switch, reads it as numeric instead of a character. Try : temp1.name - switch(temp1, 1 = aa, 2 = bb, 3 = cc, 4 = dd, 5 = ee) temp1.name [1] aa cheers Joris On Wed, Jun 9, 2010 at 12:36 PM, Megh Dal megh700...@yahoo.com wrote: Hi all, Here I am trying to implement the switch() function to choose value of a variable depending on the value of an input variable : temp1 - 1 temp1.name - switch(temp1, 1 == aa, 2 == bb, 3 == cc, 4 == dd, 5 == ee) Goal is if temp1 equals to 1, then value of temp1.name would be aa. However I am getting following answer : temp1 - 1 temp1.name - switch(temp1, + 1 == aa, + 2 == bb, + 3 == cc, + 4 == dd, + 5 == ee) temp1.name [1] FALSE Can anyone please point me where I am doing wrong? Thanks, [[alternative HTML version deleted]] __ 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 commented, minimal, self-contained, reproducible code. -- Joris Meys Statistical consultant Ghent University Faculty of Bioscience Engineering Department of Applied mathematics, biometrics and process control tel : +32 9 264 59 87 joris.m...@ugent.be --- Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php __ 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 commented, minimal, self-contained, reproducible code.
Re: [R] Help needed on switch function
PS : use a single = instead of a double. It's an assignment you do, not a comparison. Cheers Joris On Wed, Jun 9, 2010 at 2:14 PM, Joris Meys jorism...@gmail.com wrote: R is confused about the type in the switch, reads it as numeric instead of a character. Try : temp1.name - switch(temp1, 1 = aa, 2 = bb, 3 = cc, 4 = dd, 5 = ee) temp1.name [1] aa cheers Joris On Wed, Jun 9, 2010 at 12:36 PM, Megh Dal megh700...@yahoo.com wrote: Hi all, Here I am trying to implement the switch() function to choose value of a variable depending on the value of an input variable : temp1 - 1 temp1.name - switch(temp1, 1 == aa, 2 == bb, 3 == cc, 4 == dd, 5 == ee) Goal is if temp1 equals to 1, then value of temp1.name would be aa. However I am getting following answer : temp1 - 1 temp1.name - switch(temp1, + 1 == aa, + 2 == bb, + 3 == cc, + 4 == dd, + 5 == ee) temp1.name [1] FALSE Can anyone please point me where I am doing wrong? Thanks, [[alternative HTML version deleted]] __ 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 commented, minimal, self-contained, reproducible code. -- Joris Meys Statistical consultant Ghent University Faculty of Bioscience Engineering Department of Applied mathematics, biometrics and process control tel : +32 9 264 59 87 joris.m...@ugent.be --- Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php -- Joris Meys Statistical consultant Ghent University Faculty of Bioscience Engineering Department of Applied mathematics, biometrics and process control tel : +32 9 264 59 87 joris.m...@ugent.be --- Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php __ 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 commented, minimal, self-contained, reproducible code.
Re: [R] Odp: strange issue with which on seq
which(abs(v - .1) = .Machine$double.eps) seems to me too cumbersome to write. Any other easier way? all.equal does not quite work Nikhil On Jun 9, 2010, at 7:54 AM, Petr PIKAL wrote: Hi r-help-boun...@r-project.org napsal dne 09.06.2010 13:16:40: Dear R community, I am puzzled by the following lines: v - seq(-0.5,0.5,by=0.1) v [1] -0.5 -0.4 -0.3 -0.2 -0.1 0.0 0.1 0.2 0.3 0.4 0.5 which(v == -0.4) [1] 2 which(v == 0) [1] 6 which(v == 0.1) integer(0) which(v == 0.2) integer(0) which(v == 0.3) integer(0) which(v == 0.4) [1] 10 which(v == 0.5) [1] 11 Why which can only match some of the values in v? Are the numbers generated by seq not exact fractional numbers? Please, help me to understand this. Well FAQ 7.31 was not here some time. Computing in binary results in finite precision of fractional numbers. v - seq(-0.5,0.5,by=0.1) v[7]-0.1 [1] 8.326673e-17 Regards Petr J Dr James Foadi PhD Membrane Protein Laboratory (MPL) Diamond Light Source Ltd Diamond House Harewell Science and Innovation Campus Chilton, Didcot Oxfordshire OX11 0DE Email: james.fo...@diamond.ac.uk Alt Email: j.fo...@imperial.ac.uk -- This e-mail and any attachments may contain confidential... {{dropped:8}} __ 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 commented, minimal, self-contained, reproducible code. __ 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 commented, minimal, self-contained, reproducible code. __ 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 commented, minimal, self-contained, reproducible code.
[R] Odp: Help needed on switch function
Hi if you do not insist on switch you can use factor to get desired result set.seed(666) x-sample(1:5,20, replace=T) x [1] 4 1 5 2 2 4 5 3 1 2 4 1 1 1 2 5 1 5 3 3 factor(x, labels=letters[1:5]) [1] d a e b b d e c a b d a a a b e a e c c Levels: a b c d e r-help-boun...@r-project.org napsal dne 09.06.2010 12:36:26: Hi all, Here I am trying to implement the switch() function to choose value of a variable depending on the value of an input variable : temp1 - 1 temp1.name - switch(temp1, 1 == aa, 2 == bb, 3 == cc, 4 == dd, 5 == ee) Goal is if temp1 equals to 1, then value of temp1.name would be aa. However I am getting following answer : temp1 - 1 temp1.name - switch(temp1, + 1 == aa, + 2 == bb, + 3 == cc, + 4 == dd, + 5 == ee) temp1.name [1] FALSE Can anyone please point me where I am doing wrong? Have you looked at help ?switch Arguments EXPR an expression evaluating to a number or a character string. ^^ ... the list of alternatives. If it is intended that EXPR has a character-string value these will be named, perhaps except for one alternative to be used as a ‘default’ value. So in your case temp1 - 1 temp1.name - switch(temp1, 1 = aa, 2 = bb, 3 = cc, 4 = dd, 5 = ee) Basically switch compares your temp1 with all LHS alternatives, if it match it returns RHS. If it does not it will return NULL and in your case it returned probably value 1==aa which is FALSE. Regards Petr Thanks, [[alternative HTML version deleted]] __ 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 commented, minimal, self-contained, reproducible code. __ 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 commented, minimal, self-contained, reproducible code.
Re: [R] correcting a few data in an unreshaped data frame
Use indices. Eg: # a sample dataframe lupepn1 - data.frame( bushno=rep(1:2,4), bout=rep(1:4,each=2), survival=rep(0,8), wwg=rep(1,8) ) lupepn1 # select the wrong cases wrong - lupepn1$bushno==1 lupepn1$bout %in% c(1,2) # make a replacement frame replacement - rbind(c(4,5),c(9,10)) # do the replacement lupepn1[wrong,c(survival,wwg)] - replacement lupepn1 Cheers Joris On Wed, Jun 9, 2010 at 3:36 AM, Mr. Natural drstr...@ucdavis.edu wrote: Thanks for the excellent help on my recent question on this topic in which the data frame had been reshaped by cast. Now, I would like to access and change erroneous data in a data frame that has not been reshaped. The file is lupepn1, with identifier variables bushno bout and dependent variables survival, and wwG I know the bushno and bout of the erroneous dependent survival and wwG data. I could correct these in the csv file before read.data, but I would like to learn some more R head(lupepn1) bushno bout survival wwG 2 1 2 0 0 3 1 3 0 0 4 1 4 0 0 5 1 5 0 0 6 1 6 0 2 7 1 7 0 0 str(lupepn1) 'data.frame': 5023 obs. of 4 variables: $ bushno : int 1 1 1 1 1 1 1 2 2 2 ... $ bout : int 2 3 4 5 6 7 8 1 2 3 ... $ survival: int 0 0 0 0 0 0 0 1 1 1 ... $ wwG : int 0 0 0 0 2 0 0 5 1 0 ... - attr(*, na.action)=Class 'omit' Named int [1:81] 1 49 65 177 201 257 337 417 449 505 ... .. ..- attr(*, names)= chr [1:81] 1 49 65 177 ... Your kind advice is very much appreciated. Mr. Natural. -- View this message in context: http://r.789695.n4.nabble.com/correcting-a-few-data-in-an-unreshaped-data-frame-tp2248219p2248219.html Sent from the R help mailing list archive at Nabble.com. __ 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 commented, minimal, self-contained, reproducible code. -- Joris Meys Statistical consultant Ghent University Faculty of Bioscience Engineering Department of Applied mathematics, biometrics and process control tel : +32 9 264 59 87 joris.m...@ugent.be --- Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php __ 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 commented, minimal, self-contained, reproducible code.
[R] OOP and passing by value
Greetings, I love the R system and am sincerely grateful for the great effort the product and contributors are delivering. My question is as follows: I am trying to use S4 style classes but cannot write functions that modify an object because paramter passing is by value. For example I want to do this: setGeneric(setData, function(this,fcn,k){ standardGeneric(setData) }) setClass( test, representation(f=numeric, t=numeric) ) setMethod(setData,test, function(this,fcn,k){ t...@t - as.numeric(seq(-k,k))/(2*k+1) t...@f - sapply(t,FUN=fcn) } ) #--- tst - new(test) fcn - function(u){ sin(2*pi*u) } setData(tst,fcn,100) t...@t # it's still empty because of pass by value How can this be handled? Many thanks, Michael [[alternative HTML version deleted]] __ 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 commented, minimal, self-contained, reproducible code.
Re: [R] Odp: strange issue with which on seq
Hi Well, then please explain what you really want to do. I use such fractional sequences only for evaluation of some models and in that case this finite precision issue is not important. Regards Petr r-help-boun...@r-project.org napsal dne 09.06.2010 14:20:16: which(abs(v - .1) = .Machine$double.eps) seems to me too cumbersome to write. Any other easier way? all.equal does not quite work Nikhil On Jun 9, 2010, at 7:54 AM, Petr PIKAL wrote: Hi r-help-boun...@r-project.org napsal dne 09.06.2010 13:16:40: Dear R community, I am puzzled by the following lines: v - seq(-0.5,0.5,by=0.1) v [1] -0.5 -0.4 -0.3 -0.2 -0.1 0.0 0.1 0.2 0.3 0.4 0.5 which(v == -0.4) [1] 2 which(v == 0) [1] 6 which(v == 0.1) integer(0) which(v == 0.2) integer(0) which(v == 0.3) integer(0) which(v == 0.4) [1] 10 which(v == 0.5) [1] 11 Why which can only match some of the values in v? Are the numbers generated by seq not exact fractional numbers? Please, help me to understand this. Well FAQ 7.31 was not here some time. Computing in binary results in finite precision of fractional numbers. v - seq(-0.5,0.5,by=0.1) v[7]-0.1 [1] 8.326673e-17 Regards Petr J Dr James Foadi PhD Membrane Protein Laboratory (MPL) Diamond Light Source Ltd Diamond House Harewell Science and Innovation Campus Chilton, Didcot Oxfordshire OX11 0DE Email: james.fo...@diamond.ac.uk Alt Email: j.fo...@imperial.ac.uk -- This e-mail and any attachments may contain confidential... {{dropped:8}} __ 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 commented, minimal, self-contained, reproducible code. __ 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 commented, minimal, self-contained, reproducible code. __ 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 commented, minimal, self-contained, reproducible code. __ 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 commented, minimal, self-contained, reproducible code.
Re: [R] Odp: strange issue with which on seq
use ?round is the easier way v - round(seq(-0.5,0.5,by=0.1),1) On Wed, Jun 9, 2010 at 2:20 PM, Nikhil Kaza nikhil.l...@gmail.com wrote: which(abs(v - .1) = .Machine$double.eps) seems to me too cumbersome to write. Any other easier way? all.equal does not quite work Nikhil On Jun 9, 2010, at 7:54 AM, Petr PIKAL wrote: Hi r-help-boun...@r-project.org napsal dne 09.06.2010 13:16:40: Dear R community, I am puzzled by the following lines: v - seq(-0.5,0.5,by=0.1) v [1] -0.5 -0.4 -0.3 -0.2 -0.1 0.0 0.1 0.2 0.3 0.4 0.5 which(v == -0.4) [1] 2 which(v == 0) [1] 6 which(v == 0.1) integer(0) which(v == 0.2) integer(0) which(v == 0.3) integer(0) which(v == 0.4) [1] 10 which(v == 0.5) [1] 11 Why which can only match some of the values in v? Are the numbers generated by seq not exact fractional numbers? Please, help me to understand this. Well FAQ 7.31 was not here some time. Computing in binary results in finite precision of fractional numbers. v - seq(-0.5,0.5,by=0.1) v[7]-0.1 [1] 8.326673e-17 Regards Petr J Dr James Foadi PhD Membrane Protein Laboratory (MPL) Diamond Light Source Ltd Diamond House Harewell Science and Innovation Campus Chilton, Didcot Oxfordshire OX11 0DE Email : james.fo...@diamond.ac.uk Alt Email: j.fo...@imperial.ac.uk -- This e-mail and any attachments may contain confidential...{{dropped:8}} __ 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 commented, minimal, self-contained, reproducible code. __ 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 commented, minimal, self-contained, reproducible code. __ 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 commented, minimal, self-contained, reproducible code. -- Joris Meys Statistical consultant Ghent University Faculty of Bioscience Engineering Department of Applied mathematics, biometrics and process control tel : +32 9 264 59 87 joris.m...@ugent.be --- Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php __ 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 commented, minimal, self-contained, reproducible code.
Re: [R] Odp: strange issue with which on seq
On Wed, Jun 9, 2010 at 2:20 PM, Nikhil Kaza nikhil.l...@gmail.com wrote: which(abs(v - .1) = .Machine$double.eps) seems to me too cumbersome to write. Any other easier way? all.equal does not quite work See isZero() in R.utils, e.g. isZero(abs(v - 0.1)); You can adjust the precision with argument 'neps' (a scale factor of 'eps' specifying how close to close means) by: isZero(abs(v - 0.1), neps=5); The default is eps=.Machine$double.eps and neps=1. You can also do things as: isZero(abs(v - 0.1), eps=1e-4); It returns a logical vector. You have to apply which() to get the TRUE indices. /Henrik Nikhil On Jun 9, 2010, at 7:54 AM, Petr PIKAL wrote: Hi r-help-boun...@r-project.org napsal dne 09.06.2010 13:16:40: Dear R community, I am puzzled by the following lines: v - seq(-0.5,0.5,by=0.1) v [1] -0.5 -0.4 -0.3 -0.2 -0.1 0.0 0.1 0.2 0.3 0.4 0.5 which(v == -0.4) [1] 2 which(v == 0) [1] 6 which(v == 0.1) integer(0) which(v == 0.2) integer(0) which(v == 0.3) integer(0) which(v == 0.4) [1] 10 which(v == 0.5) [1] 11 Why which can only match some of the values in v? Are the numbers generated by seq not exact fractional numbers? Please, help me to understand this. Well FAQ 7.31 was not here some time. Computing in binary results in finite precision of fractional numbers. v - seq(-0.5,0.5,by=0.1) v[7]-0.1 [1] 8.326673e-17 Regards Petr J Dr James Foadi PhD Membrane Protein Laboratory (MPL) Diamond Light Source Ltd Diamond House Harewell Science and Innovation Campus Chilton, Didcot Oxfordshire OX11 0DE Email : james.fo...@diamond.ac.uk Alt Email: j.fo...@imperial.ac.uk -- This e-mail and any attachments may contain confidential...{{dropped:8}} __ 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 commented, minimal, self-contained, reproducible code. __ 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 commented, minimal, self-contained, reproducible code. __ 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 commented, minimal, self-contained, reproducible code. __ 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 commented, minimal, self-contained, reproducible code.
Re: [R] OOP and passing by value
by returning the object ? setMethod(setData,test, function(this,fcn,k){ t...@t - as.numeric(seq(-k,k))/(2*k+1) t...@f - sapply(t...@t,FUN=fcn) #changed! return(this) #changed! } ) #--- tst - new(test) fcn - function(u){ sin(2*pi*u) } New - setData(tst,fcn,5) n...@t [1] -0.4545455 -0.3636364 -0.2727273 -0.1818182 -0.0909091 0.000 0.0909091 0.1818182 0.2727273 0.3636364 0.4545455 On Wed, Jun 9, 2010 at 2:28 PM, michael meyer mjhme...@googlemail.com wrote: Greetings, I love the R system and am sincerely grateful for the great effort the product and contributors are delivering. My question is as follows: I am trying to use S4 style classes but cannot write functions that modify an object because paramter passing is by value. For example I want to do this: setGeneric(setData, function(this,fcn,k){ standardGeneric(setData) }) setClass( test, representation(f=numeric, t=numeric) ) setMethod(setData,test, function(this,fcn,k){ t...@t - as.numeric(seq(-k,k))/(2*k+1) t...@f - sapply(t,FUN=fcn) } ) #--- tst - new(test) fcn - function(u){ sin(2*pi*u) } setData(tst,fcn,100) t...@t # it's still empty because of pass by value How can this be handled? Many thanks, Michael [[alternative HTML version deleted]] __ 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 commented, minimal, self-contained, reproducible code. -- Joris Meys Statistical consultant Ghent University Faculty of Bioscience Engineering Department of Applied mathematics, biometrics and process control tel : +32 9 264 59 87 joris.m...@ugent.be --- Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php __ 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 commented, minimal, self-contained, reproducible code.
Re: [R] bootpred for multinomial
On 09.06.2010 13:26, azam jaafari wrote: I applied bootpred for multinomial logistic reg. (with nnet package). I used same as theta.fit and theta.predict of R for my data. but give me error. Can I do this with response vriable;7 levels predictor variables:5 (1 classifier, 4 continuous)? Thanks alot Azam [[alternative HTML version deleted]] __ 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 commented, minimal, self-contained, reproducible code. Yes, PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. otherwise it is hard to help without your code and without any error message. Uwe Ligges __ 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 commented, minimal, self-contained, reproducible code.
Re: [R] Problem with library(SSPA)
Same for me, but since this is a BioC package, why do you ask here? First you may report to the package maintainer or if that fails to the BioC mailing list. Best, Uwe Ligges On 09.06.2010 12:01, Samuel Okoye wrote: Hello, I have the fellowing problem and I am thankful for any advice! Regards, Samuel source(http://bioconductor.org/biocLite.R;) BioC_mirror = http://www.bioconductor.org Change using chooseBioCmirror(). biocLite(SSPA) Using R version 2.11.0, biocinstall version 2.6.7. Installing Bioconductor version 2.6 packages: [1] SSPA Please wait... trying URL 'http://www.bioconductor.org/packages/2.6/bioc/bin/windows/contrib/2.11/SSPA_1.4.0.zip' Content type 'application/zip' length 305310 bytes (298 Kb) opened URL downloaded 298 Kb package 'SSPA' successfully unpacked and MD5 sums checked library(SSPA) Loading required package: qvalue Loading required package: tcltk Loading Tcl/Tk interface ... done Error : .onAttach failed in attachNamespace() for 'SSPA', details: call: fun(...) error: could not find function addVigs2WinMenu Error: package/namespace load failed for 'SSPA' sessionInfo() R version 2.11.0 (2010-04-22) i386-pc-mingw32 locale: [1] LC_COLLATE=English_United Kingdom.1252 LC_CTYPE=English_United Kingdom.1252LC_MONETARY=English_United Kingdom.1252 [4] LC_NUMERIC=CLC_TIME=English_United Kingdom.1252 attached base packages: [1] tcltk stats graphics grDevices utils datasets methods base other attached packages: [1] qvalue_1.22.0 loaded via a namespace (and not attached): [1] limma_3.4.3 SSPA_1.4.0 tools_2.11.0 ## [[alternative HTML version deleted]] __ 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 commented, minimal, self-contained, reproducible code. __ 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 commented, minimal, self-contained, reproducible code.
Re: [R] OOP and passing by value
In case you want the function setData to change the object itself (which is often a dangerous idea!), you can use instead : setMethod(setData,test, function(this,fcn,k){ Name - deparse(substitute(this)) t...@t - as.numeric(seq(-k,k))/(2*k+1) t...@f - sapply(t...@t,FUN=fcn) assign(Name,this,.GlobalEnv) } ) #--- tst - new(test) fcn - function(u){ sin(2*pi*u) } setData(tst,fcn,5) t...@t [1] -0.4545455 -0.3636364 -0.2727273 -0.1818182 -0.0909091 0.000 0.0909091 0.1818182 0.2727273 0.3636364 0.4545455 On Wed, Jun 9, 2010 at 2:36 PM, Joris Meys jorism...@gmail.com wrote: by returning the object ? setMethod(setData,test, function(this,fcn,k){ t...@t - as.numeric(seq(-k,k))/(2*k+1) t...@f - sapply(t...@t,FUN=fcn) #changed! return(this) #changed! } ) #--- tst - new(test) fcn - function(u){ sin(2*pi*u) } New - setData(tst,fcn,5) n...@t [1] -0.4545455 -0.3636364 -0.2727273 -0.1818182 -0.0909091 0.000 0.0909091 0.1818182 0.2727273 0.3636364 0.4545455 On Wed, Jun 9, 2010 at 2:28 PM, michael meyer mjhme...@googlemail.com wrote: Greetings, I love the R system and am sincerely grateful for the great effort the product and contributors are delivering. My question is as follows: I am trying to use S4 style classes but cannot write functions that modify an object because paramter passing is by value. For example I want to do this: setGeneric(setData, function(this,fcn,k){ standardGeneric(setData) }) setClass( test, representation(f=numeric, t=numeric) ) setMethod(setData,test, function(this,fcn,k){ t...@t - as.numeric(seq(-k,k))/(2*k+1) t...@f - sapply(t,FUN=fcn) } ) #--- tst - new(test) fcn - function(u){ sin(2*pi*u) } setData(tst,fcn,100) t...@t # it's still empty because of pass by value How can this be handled? Many thanks, Michael [[alternative HTML version deleted]] __ 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 commented, minimal, self-contained, reproducible code. -- Joris Meys Statistical consultant Ghent University Faculty of Bioscience Engineering Department of Applied mathematics, biometrics and process control tel : +32 9 264 59 87 joris.m...@ugent.be --- Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php -- Joris Meys Statistical consultant Ghent University Faculty of Bioscience Engineering Department of Applied mathematics, biometrics and process control tel : +32 9 264 59 87 joris.m...@ugent.be --- Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php __ 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 commented, minimal, self-contained, reproducible code.
Re: [R] OOP and passing by value
Pass an object of, or containing an, environment. Then whenever you modify any object inside the environment, the changes will remain also when exiting from the function(s). This has been used by many for quite some time and is the standard way to do it, if you need this feature. See packages such as R.oo and proto for complete solutions. Using substitute(this) is not safe when doing nested calling, and assigning to a global environment is not something you really want to do. /Henrik On Wed, Jun 9, 2010 at 3:05 PM, Joris Meys jorism...@gmail.com wrote: In case you want the function setData to change the object itself (which is often a dangerous idea!), you can use instead : setMethod(setData,test, function(this,fcn,k){ Name - deparse(substitute(this)) t...@t - as.numeric(seq(-k,k))/(2*k+1) t...@f - sapply(t...@t,FUN=fcn) assign(Name,this,.GlobalEnv) } ) #--- tst - new(test) fcn - function(u){ sin(2*pi*u) } setData(tst,fcn,5) t...@t [1] -0.4545455 -0.3636364 -0.2727273 -0.1818182 -0.0909091 0.000 0.0909091 0.1818182 0.2727273 0.3636364 0.4545455 On Wed, Jun 9, 2010 at 2:36 PM, Joris Meys jorism...@gmail.com wrote: by returning the object ? setMethod(setData,test, function(this,fcn,k){ t...@t - as.numeric(seq(-k,k))/(2*k+1) t...@f - sapply(t...@t,FUN=fcn) #changed! return(this) #changed! } ) #--- tst - new(test) fcn - function(u){ sin(2*pi*u) } New - setData(tst,fcn,5) n...@t [1] -0.4545455 -0.3636364 -0.2727273 -0.1818182 -0.0909091 0.000 0.0909091 0.1818182 0.2727273 0.3636364 0.4545455 On Wed, Jun 9, 2010 at 2:28 PM, michael meyer mjhme...@googlemail.com wrote: Greetings, I love the R system and am sincerely grateful for the great effort the product and contributors are delivering. My question is as follows: I am trying to use S4 style classes but cannot write functions that modify an object because paramter passing is by value. For example I want to do this: setGeneric(setData, function(this,fcn,k){ standardGeneric(setData) }) setClass( test, representation(f=numeric, t=numeric) ) setMethod(setData,test, function(this,fcn,k){ t...@t - as.numeric(seq(-k,k))/(2*k+1) t...@f - sapply(t,FUN=fcn) } ) #--- tst - new(test) fcn - function(u){ sin(2*pi*u) } setData(tst,fcn,100) t...@t # it's still empty because of pass by value How can this be handled? Many thanks, Michael [[alternative HTML version deleted]] __ 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 commented, minimal, self-contained, reproducible code. -- Joris Meys Statistical consultant Ghent University Faculty of Bioscience Engineering Department of Applied mathematics, biometrics and process control tel : +32 9 264 59 87 joris.m...@ugent.be --- Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php -- Joris Meys Statistical consultant Ghent University Faculty of Bioscience Engineering Department of Applied mathematics, biometrics and process control tel : +32 9 264 59 87 joris.m...@ugent.be --- Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php __ 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 commented, minimal, self-contained, reproducible code. __ 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 commented, minimal, self-contained, reproducible code.
[R] bootpred for multinomial
Thank you very much I used bootpred for multinomial logistic reg. similar below: theta.fit - function(x,y){lsfit(x,y)} theta.predict - function(fit,x){ cbind(1,x)%*%fit$coef } sq.err - function(y,yhat) { (y-yhat)^2} results - bootpred(x,y,20,theta.fit,theta.predict, err.meas=sq.err) x=data mlr=multinom(y~x1+x2+x3+x4+x5, data) after run results: results - bootpred(data, mlr,50,theta.fit,theta.predict, sq.err) Error in as.vector(data) : no method for coercing this S4 class to a vector Is it incorrect? Azam --- On Wed, 6/9/10, Uwe Ligges lig...@statistik.tu-dortmund.de wrote: From: Uwe Ligges lig...@statistik.tu-dortmund.de Subject: Re: [R] bootpred for multinomial To: azam jaafari azamjaaf...@yahoo.com Cc: R-help r-help@r-project.org Date: Wednesday, June 9, 2010, 5:46 AM On 09.06.2010 13:26, azam jaafari wrote: I applied bootpred for multinomial logistic reg. (with nnet package). I used same as theta.fit and theta.predict of R for my data. but give me error. Can I do this with response vriable;7 levels predictor variables:5 (1 classifier, 4 continuous)? Thanks alot Azam [[alternative HTML version deleted]] __ 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 commented, minimal, self-contained, reproducible code. Yes, PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. otherwise it is hard to help without your code and without any error message. Uwe Ligges [[alternative HTML version deleted]] __ 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 commented, minimal, self-contained, reproducible code.
Re: [R] OOP and passing by value
I think you should be interested by section 5.4 (non-local assignments; closures) in Chamber's Software for Data Analysis book published in 2008 by Springer (http://www.springer.com/statistics/computanional+statistics/book/978-0-387-75935-7). Besides the solution proposed in the book, which uses assignment outside functions, there is another possibility: environment objects. They are passed by reference and there are tricks to use them in this situation, but you have to be extremely careful because you break the rules for functional programming. Don't forget generics like Data- to assign in R. See for instance help(names-). This is the most conventional and easier way to do this. Best, Philippe Grosjean On 09/06/10 14:28, michael meyer wrote: Greetings, I love the R system and am sincerely grateful for the great effort the product and contributors are delivering. My question is as follows: I am trying to use S4 style classes but cannot write functions that modify an object because paramter passing is by value. For example I want to do this: setGeneric(setData, function(this,fcn,k){ standardGeneric(setData) }) setClass( test, representation(f=numeric, t=numeric) ) setMethod(setData,test, function(this,fcn,k){ t...@t- as.numeric(seq(-k,k))/(2*k+1) t...@f- sapply(t,FUN=fcn) } ) #--- tst- new(test) fcn- function(u){ sin(2*pi*u) } setData(tst,fcn,100) t...@t # it's still empty because of pass by value How can this be handled? Many thanks, Michael [[alternative HTML version deleted]] __ 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 commented, minimal, self-contained, reproducible code. __ 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 commented, minimal, self-contained, reproducible code.
Re: [R] Problem with library(SSPA)
I can't find his email and I have asked the same question to bioconduc...@stat.math.ethz.ch Regards, Samuel --- On Wed, 9/6/10, Uwe Ligges lig...@statistik.tu-dortmund.de wrote: From: Uwe Ligges lig...@statistik.tu-dortmund.de Subject: Re: [R] Problem with library(SSPA) To: Samuel Okoye samu...@yahoo.com Cc: r-help@r-project.org Date: Wednesday, 9 June, 2010, 5:43 Same for me, but since this is a BioC package, why do you ask here? First you may report to the package maintainer or if that fails to the BioC mailing list. Best, Uwe Ligges On 09.06.2010 12:01, Samuel Okoye wrote: Hello, I have the fellowing problem and I am thankful for any advice! Regards, Samuel source(http://bioconductor.org/biocLite.R;) BioC_mirror = http://www.bioconductor.org Change using chooseBioCmirror(). biocLite(SSPA) Using R version 2.11.0, biocinstall version 2.6.7. Installing Bioconductor version 2.6 packages: [1] SSPA Please wait... trying URL 'http://www.bioconductor.org/packages/2.6/bioc/bin/windows/contrib/2.11/SSPA_1.4.0.zip' Content type 'application/zip' length 305310 bytes (298 Kb) opened URL downloaded 298 Kb package 'SSPA' successfully unpacked and MD5 sums checked library(SSPA) Loading required package: qvalue Loading required package: tcltk Loading Tcl/Tk interface ... done Error : .onAttach failed in attachNamespace() for 'SSPA', details: call: fun(...) error: could not find function addVigs2WinMenu Error: package/namespace load failed for 'SSPA' sessionInfo() R version 2.11.0 (2010-04-22) i386-pc-mingw32 locale: [1] LC_COLLATE=English_United Kingdom.1252 LC_CTYPE=English_United Kingdom.1252 LC_MONETARY=English_United Kingdom.1252 [4] LC_NUMERIC=C LC_TIME=English_United Kingdom.1252 attached base packages: [1] tcltk stats graphics grDevices utils datasets methods base other attached packages: [1] qvalue_1.22.0 loaded via a namespace (and not attached): [1] limma_3.4.3 SSPA_1.4.0 tools_2.11.0 ## [[alternative HTML version deleted]] __ 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 commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ 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 commented, minimal, self-contained, reproducible code.
Re: [R] Problem with library(SSPA)
On 09.06.2010 15:19, Samuel Okoye wrote: I can't find his email packageDescription(SSPA) and I have asked the same question to bioconduc...@stat.math.ethz.ch Regards, Samuel --- On Wed, 9/6/10, Uwe Liggeslig...@statistik.tu-dortmund.de wrote: From: Uwe Liggeslig...@statistik.tu-dortmund.de Subject: Re: [R] Problem with library(SSPA) To: Samuel Okoyesamu...@yahoo.com Cc: r-help@r-project.org Date: Wednesday, 9 June, 2010, 5:43 Same for me, but since this is a BioC package, why do you ask here? First you may report to the package maintainer or if that fails to the BioC mailing list. Best, Uwe Ligges On 09.06.2010 12:01, Samuel Okoye wrote: Hello, I have the fellowing problem and I am thankful for any advice! Regards, Samuel source(http://bioconductor.org/biocLite.R;) BioC_mirror = http://www.bioconductor.org Change using chooseBioCmirror(). biocLite(SSPA) Using R version 2.11.0, biocinstall version 2.6.7. Installing Bioconductor version 2.6 packages: [1] SSPA Please wait... trying URL 'http://www.bioconductor.org/packages/2.6/bioc/bin/windows/contrib/2.11/SSPA_1.4.0.zip' Content type 'application/zip' length 305310 bytes (298 Kb) opened URL downloaded 298 Kb package 'SSPA' successfully unpacked and MD5 sums checked library(SSPA) Loading required package: qvalue Loading required package: tcltk Loading Tcl/Tk interface ... done Error : .onAttach failed in attachNamespace() for 'SSPA', details: call: fun(...) error: could not find function addVigs2WinMenu Error: package/namespace load failed for 'SSPA' sessionInfo() R version 2.11.0 (2010-04-22) i386-pc-mingw32 locale: [1] LC_COLLATE=English_United Kingdom.1252 LC_CTYPE=English_United Kingdom.1252LC_MONETARY=English_United Kingdom.1252 [4] LC_NUMERIC=CLC_TIME=English_United Kingdom.1252 attached base packages: [1] tcltk stats graphics grDevices utils datasets methods base other attached packages: [1] qvalue_1.22.0 loaded via a namespace (and not attached): [1] limma_3.4.3 SSPA_1.4.0 tools_2.11.0 ## [[alternative HTML version deleted]] __ 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 commented, minimal, self-contained, reproducible code. __ 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 commented, minimal, self-contained, reproducible code.
[R] RGoogleDocs not working for me with wise service
Hello, I'm trying to figure out how to use the RGoogleDocs package from OmegaHat, and am having a bit of trouble. I emailed Duncan Temple Lang directly, but didn't receive a response, so I thought I'd try here to see if anyone else can help. I'm using 32-bit R 2.10.1 (Mac OS X), I built RGoogleDocs 0.4-0 from source, and I'm using XML 3.1-0 and RCurl 1.2-0. If I use service=wise in getGoogleDocsConnection, I then get this error: getDocs(con) Error in getDocs(con) : problems connecting to get the list of documents tracing through I get: Browse[1] status WWW-Authenticate GoogleLogin realm=\http://www.google.com/accounts/ClientLogin\http://www.google.com/accounts/ClientLogin%5C, service=\writely\ Content-Type text/html; charset=UTF-8 Date Fri, 04 Jun 2010 16:22:19 GMT Expires Fri, 04 Jun 2010 16:22:19 GMT Cache-Control private, max-age=0 X-Content-Type-Options nosniff X-Frame-Options SAMEORIGIN X-XSS-Protection 1; mode=block Server GSE Transfer-Encoding chunked status 401 statusMessage Token invalid If I don't use service=wise, getDocs(con) properly returns a GoogleDocList. (But, of course, I can't manipulate spreadsheet content...) Any suggestions? Is it a package version issue, perhaps? Has Google updated their API in a way that hasn't been reflected in updates to this package? Thanks a lot! -Harlan [[alternative HTML version deleted]] __ 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 commented, minimal, self-contained, reproducible code.
[R] changing the number of elements in a list
I would like to have a list where each element is a matrix, for example: my.list - list(matrix(0, ncol=3, nrow=3), matrix(0, ncol=3, nrow=3), matrix(0, ncol=3, nrow=3)) The problem is, I would like to be able to change automatically the number of elements in the list (not only three as in the above example). That is, the instruction creating the list would be a part of a function that has an inputing parameter stating how many elements (matrices) the list has. I have tried several things, but none worked. However, this seems to be a rather simple problem. All help is welcome! LBA __ 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 commented, minimal, self-contained, reproducible code.
Re: [R] Problem with library(SSPA)
Dear Maarten, I have problem to use your package and I would be very thankful if you could help me to solve this. Regards, Samuel --- On Wed, 9/6/10, Uwe Ligges lig...@statistik.tu-dortmund.de wrote: From: Uwe Ligges lig...@statistik.tu-dortmund.de Subject: Re: [R] Problem with library(SSPA) To: Samuel Okoye samu...@yahoo.com Cc: r-help@r-project.org Date: Wednesday, 9 June, 2010, 6:43 On 09.06.2010 15:19, Samuel Okoye wrote: I can't find his email packageDescription(SSPA) and I have asked the same question to bioconduc...@stat.math.ethz.ch Regards, Samuel --- On Wed, 9/6/10, Uwe Liggeslig...@statistik.tu-dortmund.de wrote: From: Uwe Liggeslig...@statistik.tu-dortmund.de Subject: Re: [R] Problem with library(SSPA) To: Samuel Okoyesamu...@yahoo.com Cc: r-help@r-project.org Date: Wednesday, 9 June, 2010, 5:43 Same for me, but since this is a BioC package, why do you ask here? First you may report to the package maintainer or if that fails to the BioC mailing list. Best, Uwe Ligges On 09.06.2010 12:01, Samuel Okoye wrote: Hello, I have the fellowing problem and I am thankful for any advice! Regards, Samuel source(http://bioconductor.org/biocLite.R;) BioC_mirror = http://www.bioconductor.org Change using chooseBioCmirror(). biocLite(SSPA) Using R version 2.11.0, biocinstall version 2.6.7. Installing Bioconductor version 2.6 packages: [1] SSPA Please wait... trying URL 'http://www.bioconductor.org/packages/2.6/bioc/bin/windows/contrib/2.11/SSPA_1.4.0.zip' Content type 'application/zip' length 305310 bytes (298 Kb) opened URL downloaded 298 Kb package 'SSPA' successfully unpacked and MD5 sums checked library(SSPA) Loading required package: qvalue Loading required package: tcltk Loading Tcl/Tk interface ... done Error : .onAttach failed in attachNamespace() for 'SSPA', details: call: fun(...) error: could not find function addVigs2WinMenu Error: package/namespace load failed for 'SSPA' sessionInfo() R version 2.11.0 (2010-04-22) i386-pc-mingw32 locale: [1] LC_COLLATE=English_United Kingdom.1252 LC_CTYPE=English_United Kingdom.1252 LC_MONETARY=English_United Kingdom.1252 [4] LC_NUMERIC=C LC_TIME=English_United Kingdom.1252 attached base packages: [1] tcltk stats graphics grDevices utils datasets methods base other attached packages: [1] qvalue_1.22.0 loaded via a namespace (and not attached): [1] limma_3.4.3 SSPA_1.4.0 tools_2.11.0 ## [[alternative HTML version deleted]] __ 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 commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ 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 commented, minimal, self-contained, reproducible code.
Re: [R] changing the number of elements in a list
Hi, What about: my.list - vector(mode=list, length=number_of_matrices) ? HTH, Ivan Le 6/9/2010 15:46, Luis Borda de Agua a écrit : I would like to have a list where each element is a matrix, for example: my.list- list(matrix(0, ncol=3, nrow=3), matrix(0, ncol=3, nrow=3), matrix(0, ncol=3, nrow=3)) The problem is, I would like to be able to change automatically the number of elements in the list (not only three as in the above example). That is, the instruction creating the list would be a part of a function that has an inputing parameter stating how many elements (matrices) the list has. I have tried several things, but none worked. However, this seems to be a rather simple problem. All help is welcome! LBA __ 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 commented, minimal, self-contained, reproducible code. -- Ivan CALANDRA PhD Student University of Hamburg Biozentrum Grindel und Zoologisches Museum Abt. Säugetiere Martin-Luther-King-Platz 3 D-20146 Hamburg, GERMANY +49(0)40 42838 6231 ivan.calan...@uni-hamburg.de ** http://www.for771.uni-bonn.de http://webapp5.rrz.uni-hamburg.de/mammals/eng/mitarbeiter.php __ 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 commented, minimal, self-contained, reproducible code.
Re: [R] changing the number of elements in a list
I might give this a try as well: my.list - replicate(3, matrix(0, ncol=3, nrow=3), simplify=FALSE) args(replicate) function (n, expr, simplify = TRUE) replicate(3, matrix(0, ncol=3, nrow=3), simplify=FALSE) [[1]] [,1] [,2] [,3] [1,]000 [2,]000 [3,]000 [[2]] [,1] [,2] [,3] [1,]000 [2,]000 [3,]000 [[3]] [,1] [,2] [,3] [1,]000 [2,]000 [3,]000 is.list(replicate(3, matrix(0, ncol=3, nrow=3), simplify=FALSE)) [1] TRUE Bill On Jun 9, 2010, at 9:54 AM, Ivan Calandra wrote: Hi, What about: my.list - vector(mode=list, length=number_of_matrices) ? HTH, Ivan Le 6/9/2010 15:46, Luis Borda de Agua a écrit : I would like to have a list where each element is a matrix, for example: my.list- list(matrix(0, ncol=3, nrow=3), matrix(0, ncol=3, nrow=3), matrix(0, ncol=3, nrow=3)) The problem is, I would like to be able to change automatically the number of elements in the list (not only three as in the above example). That is, the instruction creating the list would be a part of a function that has an inputing parameter stating how many elements (matrices) the list has. I have tried several things, but none worked. However, this seems to be a rather simple problem. All help is welcome! LBA __ 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 commented, minimal, self-contained, reproducible code. -- Ivan CALANDRA PhD Student University of Hamburg Biozentrum Grindel und Zoologisches Museum Abt. Säugetiere Martin-Luther-King-Platz 3 D-20146 Hamburg, GERMANY +49(0)40 42838 6231 ivan.calan...@uni-hamburg.de ** http://www.for771.uni-bonn.de http://webapp5.rrz.uni-hamburg.de/mammals/eng/mitarbeiter.php __ 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 commented, minimal, self-contained, reproducible code. __ 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 commented, minimal, self-contained, reproducible code.
Re: [R] OOP and passing by value
Thanks for the correction. Personally, I never really use that kind of assignments, and the deparse(substitute()) construct I only use in self-defined plotting functions in simple scripts to be run on series of equivalent datasets by me, myself and I. When writing a package with nested functions and the likes, there are indeed far better solutions than this one. I am -obviously- not an expert on those. And honestly, I personally don't like the idea of a function changing my object. So in conclusion, I shouldn't even have sent my last mail I guess... Cheers Joris On Wed, Jun 9, 2010 at 3:12 PM, Henrik Bengtsson h...@stat.berkeley.edu wrote: Pass an object of, or containing an, environment. Then whenever you modify any object inside the environment, the changes will remain also when exiting from the function(s). This has been used by many for quite some time and is the standard way to do it, if you need this feature. See packages such as R.oo and proto for complete solutions. Using substitute(this) is not safe when doing nested calling, and assigning to a global environment is not something you really want to do. /Henrik On Wed, Jun 9, 2010 at 3:05 PM, Joris Meys jorism...@gmail.com wrote: In case you want the function setData to change the object itself (which is often a dangerous idea!), you can use instead : setMethod(setData,test, function(this,fcn,k){ Name - deparse(substitute(this)) t...@t - as.numeric(seq(-k,k))/(2*k+1) t...@f - sapply(t...@t,FUN=fcn) assign(Name,this,.GlobalEnv) } ) #--- tst - new(test) fcn - function(u){ sin(2*pi*u) } setData(tst,fcn,5) t...@t [1] -0.4545455 -0.3636364 -0.2727273 -0.1818182 -0.0909091 0.000 0.0909091 0.1818182 0.2727273 0.3636364 0.4545455 On Wed, Jun 9, 2010 at 2:36 PM, Joris Meys jorism...@gmail.com wrote: by returning the object ? setMethod(setData,test, function(this,fcn,k){ t...@t - as.numeric(seq(-k,k))/(2*k+1) t...@f - sapply(t...@t,FUN=fcn) #changed! return(this) #changed! } ) #--- tst - new(test) fcn - function(u){ sin(2*pi*u) } New - setData(tst,fcn,5) n...@t [1] -0.4545455 -0.3636364 -0.2727273 -0.1818182 -0.0909091 0.000 0.0909091 0.1818182 0.2727273 0.3636364 0.4545455 On Wed, Jun 9, 2010 at 2:28 PM, michael meyer mjhme...@googlemail.com wrote: Greetings, I love the R system and am sincerely grateful for the great effort the product and contributors are delivering. My question is as follows: I am trying to use S4 style classes but cannot write functions that modify an object because paramter passing is by value. For example I want to do this: setGeneric(setData, function(this,fcn,k){ standardGeneric(setData) }) setClass( test, representation(f=numeric, t=numeric) ) setMethod(setData,test, function(this,fcn,k){ t...@t - as.numeric(seq(-k,k))/(2*k+1) t...@f - sapply(t,FUN=fcn) } ) #--- tst - new(test) fcn - function(u){ sin(2*pi*u) } setData(tst,fcn,100) t...@t # it's still empty because of pass by value How can this be handled? Many thanks, Michael [[alternative HTML version deleted]] __ 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 commented, minimal, self-contained, reproducible code. -- Joris Meys Statistical consultant Ghent University Faculty of Bioscience Engineering Department of Applied mathematics, biometrics and process control tel : +32 9 264 59 87 joris.m...@ugent.be --- Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php -- Joris Meys Statistical consultant Ghent University Faculty of Bioscience Engineering Department of Applied mathematics, biometrics and process control tel : +32 9 264 59 87 joris.m...@ugent.be --- Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php __ 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 commented, minimal, self-contained, reproducible code. -- Joris Meys Statistical consultant Ghent University Faculty of Bioscience Engineering Department of Applied mathematics, biometrics and process control tel : +32 9 264 59 87 joris.m...@ugent.be --- Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide
[R] Odp: changing the number of elements in a list
Hi one option is to create an empty list with my.list - vector(list, n) where n is number of elements in list. Then you can populate each element by my.list[[x]] - something where x can be number or my.list[x] -something where x is numeric vector Regards Petr r-help-boun...@r-project.org napsal dne 09.06.2010 15:46:09: I would like to have a list where each element is a matrix, for example: my.list - list(matrix(0, ncol=3, nrow=3), matrix(0, ncol=3, nrow=3), matrix(0, ncol=3, nrow=3)) The problem is, I would like to be able to change automatically the number of elements in the list (not only three as in the above example). That is, the instruction creating the list would be a part of a function that has an inputing parameter stating how many elements (matrices) the list has. I have tried several things, but none worked. However, this seems to be a rather simple problem. All help is welcome! LBA __ 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 commented, minimal, self-contained, reproducible code. __ 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 commented, minimal, self-contained, reproducible code.
Re: [R] bootpred for multinomial
On 09.06.2010 15:15, azam jaafari wrote: Thank you very much I used bootpred for multinomial logistic reg. similar below: theta.fit- function(x,y){lsfit(x,y)} theta.predict- function(fit,x){ cbind(1,x)%*%fit$coef } sq.err- function(y,yhat) { (y-yhat)^2} results- bootpred(x,y,20,theta.fit,theta.predict, err.meas=sq.err) x=data mlr=multinom(y~x1+x2+x3+x4+x5, data) after run results: results- bootpred(data, mlr,50,theta.fit,theta.predict, sq.err) Error in as.vector(data) : no method for coercing this S4 class to a vector Is it incorrect? First guess: bootpred() is from the bootstrap packages (you just told about nnet). From that help page (?bootpred): x a matrix containing the predictor (regressor) values. Each row corresponds to an observation. And your data is some S4 class object, obviously, but bootpred expects a matrix according to the docs Uwe Ligges Azam --- On Wed, 6/9/10, Uwe Liggeslig...@statistik.tu-dortmund.de wrote: From: Uwe Liggeslig...@statistik.tu-dortmund.de Subject: Re: [R] bootpred for multinomial To: azam jaafariazamjaaf...@yahoo.com Cc: R-helpr-help@r-project.org Date: Wednesday, June 9, 2010, 5:46 AM On 09.06.2010 13:26, azam jaafari wrote: I applied bootpred for multinomial logistic reg. (with nnet package). I used same as theta.fit and theta.predict of R for my data. but give me error. Can I do this with response vriable;7 levels predictor variables:5 (1 classifier, 4 continuous)? Thanks alot Azam [[alternative HTML version deleted]] __ 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 commented, minimal, self-contained, reproducible code. Yes, PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. otherwise it is hard to help without your code and without any error message. Uwe Ligges [[alternative HTML version deleted]] __ 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 commented, minimal, self-contained, reproducible code. __ 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 commented, minimal, self-contained, reproducible code.
[R] How to add a new plot in the same graph using add=T at the command plot?
Hi, there! I'm having kind this same problem https://stat.ethz.ch/pipermail/r-help/2008-October/178221.html but I want to display another plot of my data, which is a point with two arrows indicating confidence interval, in the same graph that I've just plotted another, but the add=T is not functioning, I'm getting the same error Warning messages: 1: In plot.window(...) : add não é um parâmetro gráfico 2: In plot.xy(xy, type, ...) : add não é um parâmetro gráfico 3: In axis(side = side, at = at, labels = labels, ...) : add não é um parâmetro gráfico 4: In axis(side = side, at = at, labels = labels, ...) : add não é um parâmetro gráfico 5: In box(...) : add não é um parâmetro gráfico 6: In title(...) : add não é um parâmetro gráfico In all tutorials I search, I see that the form of doing that is using the add=T... Is there another way? Thanks in advance! -- Larissa [[alternative HTML version deleted]] __ 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 commented, minimal, self-contained, reproducible code.
Re: [R] How to add a new plot in the same graph using add=T at the command plot?
I forgot to show my code... it is like this jpeg() plot(x,y,main=str, xlab=str,ylab=str, axes=FALSE) axis(1,at=seq(0,4.5,by=0.5),pos=0) axis(2,at=seq(0,100,by=1.0),pos=0) arrows(x, y, x, ic_esq, length=0.1, angle=90, code=3) arrows(x, y, x, ic_dir, length=0.1, angle=90, code=3) plot(x1,y1, add=T) Warning messages: 1: In plot.window(...) : add não é um parâmetro gráfico 2: In plot.xy(xy, type, ...) : add não é um parâmetro gráfico 3: In axis(side = side, at = at, labels = labels, ...) : add não é um parâmetro gráfico 4: In axis(side = side, at = at, labels = labels, ...) : add não é um parâmetro gráfico 5: In box(...) : add não é um parâmetro gráfico 6: In title(...) : add não é um parâmetro gráfico Thanks On Wed, Jun 9, 2010 at 11:29, Larissa Lucena larissaluc...@gmail.comwrote: Hi, there! I'm having kind this same problem https://stat.ethz.ch/pipermail/r-help/2008-October/178221.html but I want to display another plot of my data, which is a point with two arrows indicating confidence interval, in the same graph that I've just plotted another, but the add=T is not functioning, I'm getting the same error Warning messages: 1: In plot.window(...) : add não é um parâmetro gráfico 2: In plot.xy(xy, type, ...) : add não é um parâmetro gráfico 3: In axis(side = side, at = at, labels = labels, ...) : add não é um parâmetro gráfico 4: In axis(side = side, at = at, labels = labels, ...) : add não é um parâmetro gráfico 5: In box(...) : add não é um parâmetro gráfico 6: In title(...) : add não é um parâmetro gráfico In all tutorials I search, I see that the form of doing that is using the add=T... Is there another way? Thanks in advance! -- Larissa -- Larissa [[alternative HTML version deleted]] __ 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 commented, minimal, self-contained, reproducible code.
Re: [R] How to add a new plot in the same graph using add=T at the command plot?
Hi where did you find parameter add=T. You can use par(new=T) before using new plot command or use points, lines Regards Petr r-help-boun...@r-project.org napsal dne 09.06.2010 16:42:25: I forgot to show my code... it is like this jpeg() plot(x,y,main=str, xlab=str,ylab=str, axes=FALSE) axis(1,at=seq(0,4.5,by=0.5),pos=0) axis(2,at=seq(0,100,by=1.0),pos=0) arrows(x, y, x, ic_esq, length=0.1, angle=90, code=3) arrows(x, y, x, ic_dir, length=0.1, angle=90, code=3) plot(x1,y1, add=T) Warning messages: 1: In plot.window(...) : add năo é um parâmetro gráfico 2: In plot.xy(xy, type, ...) : add năo é um parâmetro gráfico 3: In axis(side = side, at = at, labels = labels, ...) : add năo é um parâmetro gráfico 4: In axis(side = side, at = at, labels = labels, ...) : add năo é um parâmetro gráfico 5: In box(...) : add năo é um parâmetro gráfico 6: In title(...) : add năo é um parâmetro gráfico Thanks On Wed, Jun 9, 2010 at 11:29, Larissa Lucena larissaluc...@gmail.comwrote: Hi, there! I'm having kind this same problem https://stat.ethz.ch/pipermail/r-help/2008-October/178221.html but I want to display another plot of my data, which is a point with two arrows indicating confidence interval, in the same graph that I've just plotted another, but the add=T is not functioning, I'm getting the same error Warning messages: 1: In plot.window(...) : add năo é um parâmetro gráfico 2: In plot.xy(xy, type, ...) : add năo é um parâmetro gráfico 3: In axis(side = side, at = at, labels = labels, ...) : add năo é um parâmetro gráfico 4: In axis(side = side, at = at, labels = labels, ...) : add năo é um parâmetro gráfico 5: In box(...) : add năo é um parâmetro gráfico 6: In title(...) : add năo é um parâmetro gráfico In all tutorials I search, I see that the form of doing that is using the add=T... Is there another way? Thanks in advance! -- Larissa -- Larissa [[alternative HTML version deleted]] __ 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 commented, minimal, self-contained, reproducible code. __ 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 commented, minimal, self-contained, reproducible code.
Re: [R] How to add a new plot in the same graph using add=T at the command plot?
Thanks so much!!! I'm using R for the first time, and so, I have many stupid doubts! Sorry and thanks again! Regards! 2010/6/9 Petr PIKAL petr.pi...@precheza.cz Hi where did you find parameter add=T. You can use par(new=T) before using new plot command or use points, lines Regards Petr r-help-boun...@r-project.org napsal dne 09.06.2010 16:42:25: I forgot to show my code... it is like this jpeg() plot(x,y,main=str, xlab=str,ylab=str, axes=FALSE) axis(1,at=seq(0,4.5,by=0.5),pos=0) axis(2,at=seq(0,100,by=1.0),pos=0) arrows(x, y, x, ic_esq, length=0.1, angle=90, code=3) arrows(x, y, x, ic_dir, length=0.1, angle=90, code=3) plot(x1,y1, add=T) Warning messages: 1: In plot.window(...) : add nÄo é um parâmetro gráfico 2: In plot.xy(xy, type, ...) : add nÄo é um parâmetro gráfico 3: In axis(side = side, at = at, labels = labels, ...) : add nÄo é um parâmetro gráfico 4: In axis(side = side, at = at, labels = labels, ...) : add nÄo é um parâmetro gráfico 5: In box(...) : add nÄo é um parâmetro gráfico 6: In title(...) : add nÄo é um parâmetro gráfico Thanks On Wed, Jun 9, 2010 at 11:29, Larissa Lucena larissaluc...@gmail.comwrote: Hi, there! I'm having kind this same problem https://stat.ethz.ch/pipermail/r-help/2008-October/178221.html but I want to display another plot of my data, which is a point with two arrows indicating confidence interval, in the same graph that I've just plotted another, but the add=T is not functioning, I'm getting the same error Warning messages: 1: In plot.window(...) : add nÄo é um parâmetro gráfico 2: In plot.xy(xy, type, ...) : add nÄo é um parâmetro gráfico 3: In axis(side = side, at = at, labels = labels, ...) : add nÄo é um parâmetro gráfico 4: In axis(side = side, at = at, labels = labels, ...) : add nÄo é um parâmetro gráfico 5: In box(...) : add nÄo é um parâmetro gráfico 6: In title(...) : add nÄo é um parâmetro gráfico In all tutorials I search, I see that the form of doing that is using the add=T... Is there another way? Thanks in advance! -- Larissa -- Larissa [[alternative HTML version deleted]] __ 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 commented, minimal, self-contained, reproducible code. -- Larissa [[alternative HTML version deleted]] __ 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 commented, minimal, self-contained, reproducible code.
[R] comparing two regression models with different dependent variable
Hi, I would like to compare to regression models - each model has a different dependent variable. The first model uses a number that represents the learning curve for reward. The second model uses a number that represents the learning curve from punishment stimuli. The first model is significant and the second isn't. I want to compare those two models and show that they are significantly different. How can I do that? Thank you. [[alternative HTML version deleted]] __ 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 commented, minimal, self-contained, reproducible code.
Re: [R] equivalent of stata command in R
If you don't know how to proceed, you should look for a good book on statistics. I checked the .nlcom, and what it does is give estimates and tests on a (nonlinear) combination of estimated parameters. That's doable, but a bit tedious to program. It is basically using the rules on the adding and multiplication of random variables and standard errors. but the interpretation is also not that straightforward. In the generalized mixed model world, the appropriate way of estimating the marginal effects you're looking for (I guess...) is centering your data around the mean before fitting the model. That way, the parameter of the main effect represent exactly the marginal effect at the sample mean for the other variables, simply because the mean is 0 for all of them and the equation you use simplifies to _b[eco]. Yet, the test statistic only gives you an idea about whether or not this coefficient differs from zero, assuming it is normally distributed with se as calculated. That is not the same as testing whether there is a significant marginal effect. Marginal effects are in my opinion better tested using likelihood ratio methods. These are not provided in plm, as that one is based on generalized least squares and hence does not return a likelihood value. To use LR tests, you'll have to go to nlme or lme4. Following is an obligatory read if you're going to use plm methods : http://cran.r-project.org/web/packages/plm/vignettes/plm.pdf Maybe you better contact the maintainer of the package yves.croiss...@let.ish-lyon.cnrs.fr directly to ask for the correct testing procedure for your hypothesis, because I'm still not sure that you're doing the fitting correctly in R. Just like you specify fe i(stno) in Stata, you should specify index=stno in the R command. Cheers Joris On Wed, Jun 9, 2010 at 1:27 PM, mike mick saint-fi...@hotmail.com wrote: Thanx for your response, yeah, i know i didnst specified the indexes when i wrote the 2nd mail, in fact in the 1st mail i wrote already that i dont have problem with the estimation of the model... thats the reason why i didnt write in fact since the issue is not to estimate the model but to get the marginal effect, anyway, i figured out that predict(), doesnt work for panel data... and well, my problem is that contrary to your guess, i couldnt figure out the rest of the calculations... since i am not that experienced in R. one last help of yours would be quite helpful to get rid of this silly problem! Thanx again... -- Joris Meys Statistical consultant Ghent University Faculty of Bioscience Engineering Department of Applied mathematics, biometrics and process control tel : +32 9 264 59 87 joris.m...@ugent.be --- Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php __ 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 commented, minimal, self-contained, reproducible code.
[R] Plotting Question
Hello, I would like to produce a series of graphs comparing the probability distributions for 8 factors against a continuous metric. The kind of graph I'm hoping to produce would look like the density comparison graphs (library sm) using the function sm.density.compare. However, instead of calculating the density distributions for comparisons, I'd like this comparison to be based on probabilities. An example of the graph I'm seeking can be seen here: http://www.statmethods.net/graphs/density.html (scroll to the bottom and examine the Comparing Groups via Kernel Density). A graph (attached) produced using my data: attach(SoilVegHydro) vegtype.f - factor(Physiogomy) sm.density.compare(meanAnnualDepthAve, vegtype.f, xlab=Mean Annual Depth) # create color fill patterns colfill - c(2:(2+length(levels(vegtype.f legend(locator(1), levels(vegtype.f), fill=colfill) (See attached file: MeanAnnualDepth_Density.png) Thanks Steve Steve Friedman Ph. D. Spatial Statistical Analyst Everglades and Dry Tortugas National Park 950 N Krome Ave (3rd Floor) Homestead, Florida 33034 steve_fried...@nps.gov Office (305) 224 - 4282 Fax (305) 224 - 4147attachment: MeanAnnualDepth_Density.png__ 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 commented, minimal, self-contained, reproducible code.
Re: [R] comparing two regression models with different dependentvariable
1. This is not an R question. 2. What you have requested is nonsense. You need to consult your local statistician. Bert Gunter Genentech Nonclinical Statistics -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Or Duek Sent: Wednesday, June 09, 2010 8:20 AM To: R-help@r-project.org Subject: [R] comparing two regression models with different dependentvariable Hi, I would like to compare to regression models - each model has a different dependent variable. The first model uses a number that represents the learning curve for reward. The second model uses a number that represents the learning curve from punishment stimuli. The first model is significant and the second isn't. I want to compare those two models and show that they are significantly different. How can I do that? Thank you. [[alternative HTML version deleted]] __ 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 commented, minimal, self-contained, reproducible code. __ 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 commented, minimal, self-contained, reproducible code.
[R] generate list of variable names
Hi! Would anyone know how to generate a list of variable names from a data frame by the class of the variable? I have large tables with different numbers of columns and am trying to script some rote analyses. There are several categorizing variables (factors) and many response variables (integers and numeric). I want to extract a list of classifier column names in one list and response variable names in another list, then run for-loops to calculate various statistics on the response variables in terms of the classifier variables. I thought something like this might work (but didn't): tmp-dataframe for (i in 1:length(tmp)){ if(class(tmp[[i]]==factor) else tmp[[i]]-NULL } factorlist-names(tmp) ... One problem is that the scope of the counter changes as I drop columns, but there seems to be other problems as well Any suggestions would be welcome. Thanks! Jon Soli Deo Gloria Jon Erik Ween, MD, MS Scientist, Kunin-Lunenfeld Applied Research Unit Director, Stroke Clinic, Brain Health Clinic, Baycrest Centre Assistant Professor, Dept. of Medicine, Div. of Neurology University of Toronto Faculty of Medicine Kimel Family Building, 6th Floor, Room 644 Baycrest Centre 3560 Bathurst Street Toronto, Ontario M6A 2E1 Canada Phone: 416-785-2500 x3648 Fax: 416-785-2484 Email: jw...@klaru-baycrest.on.ca Confidential: This communication and any attachment(s) may contain confidential or privileged information and is intended solely for the address(es) or the entity representing the recipient(s). If you have received this information in error, you are hereby advised to destroy the document and any attachment(s), make no copies of same and inform the sender immediately of the error. Any unauthorized use or disclosure of this information is strictly prohibited. [[alternative HTML version deleted]] __ 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 commented, minimal, self-contained, reproducible code.
Re: [R] Draw text with a box surround in plot.
Rectangle R centered at (x,y) with width 2w and height 2h is given by x1=x-w y1=y-h x2=x+w y2=y-h x3=x+w y3=y+h x4=x-w y4=y+h polygon(c(x1,x2,x3,x4),c(y1,y2,y3,y4)) Rotating a point (u,v) at (0,0) by theta degree is given by matrix [cos(theta),-sin(theta) sin(theta),cos(theta)] so we have a new point (u*cos(theta)-v*sin(theta),u*sin(theta)+v*cos(theta)). Hence rotated R by theta at (x,y) is given by x.rotated = c(x + (x1-x)*cos(theta)-(y1-y)*sin(theta), x + (x2-x)*cos(theta)-(y2-y)*sin(theta), x + (x3-x)*cos(theta)-(y3-y)*sin(theta), x + (x4-x)*cos(theta)-(y4-y)*sin(theta)) y.rotated = c(y + (x1-x)*sin(theta)+(y1-y)*cos(theta), y + (x2-x)*sin(theta)+(y2-y)*cos(theta), y + (x3-x)*sin(theta)+(y3-y)*cos(theta), y + (x4-x)*sin(theta)+(y4-y)*cos(theta)) polygon(x.rotated,y.rotated) But it turns out to be a parallelogram with angles not equal to 90, not a rectangle. See R code below. Any way to improve this so that the rotated rectangle looks like a rectangle? Thanks, -james plot(1:10,1:10,xlim=c(1,20),ylim=c(1,40),type=n, main = Rotated rectangle looks like a ) ## a rect at (10,20) with w = 3 and h = 2 x = 10 y = 20 w = 3 h = 2 x1=x-w y1=y-h x2=x+w y2=y-h x3=x+w y3=y+h x4=x-w y4=y+h polygon(c(x1,x2,x3,x4),c(y1,y2,y3,y4),border=blue) ##Rotate it at (10,10) by 45 degree theta = 45/180*pi x.rotated = c(10 + (x1-10)*cos(theta)-(y1-20)*sin(theta), 10 + (x2-10)*cos(theta)-(y2-20)*sin(theta), 10 + (x3-10)*cos(theta)-(y3-20)*sin(theta), 10 + (x4-10)*cos(theta)-(y4-20)*sin(theta)) y.rotated = c(20 + (x1-10)*sin(theta)+(y1-20)*cos(theta), 20 + (x2-10)*sin(theta)+(y2-20)*cos(theta), 20 + (x3-10)*sin(theta)+(y3-20)*cos(theta), 20 + (x4-10)*sin(theta)+(y4-20)*cos(theta)) polygon(x.rotated,y.rotated,border=red) On 06/04/2010 01:21 AM, g...@ucalgary.ca wrote: boxed.labels draw text with box well. But, the box cannot be shadowed and srt = 45 seems not to work: text is rotated but the box does not. polygon.shadow can rotate and shadow but have to calculate its dimensions, based on the text length and size. Do you have any other way to draw text with rotated and shadowed box? The srt argument was intended to allow the user to rotate the text in 90 degree increments, and the box just changes shape to fit whatever is in it. The underlying function that draws the box (rect) doesn't have a rotation argument. It would be possible to write a special function using polygon, just do the calculations for box size and then rotate the text with srt= and the polygon by transforming the coordinates of the vertices, as long as the default justification (center) is used. I can't do this right at the moment, but if you are really stuck I might be able to do it in the near future. Jim __ 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 commented, minimal, self-contained, reproducible code.
[R] help for generating data from ar1 like model
Hi all, I wrote the following function to generate data following a mixture-ar1 model. The model is described as below: theta is a m-vector with each entries identically and independent Bernoulli trials with success probability pi1. x is a m-vector with entries follow a ar1 model x_{i+1}=rho * x_{i} + e_{i} + mu1 * theta[i]''. In other words, the dependence is like ar1 model, however, the mean is mu1 or 0 according to whether theta is 1 or 0. I am not too familar with the r functions generating time series data. Can some one have a look at the function I wrote? Thank you very much! rdata.mix.ar1-function(pi1,m, rho, mu1) { ## generate data from the following mixture-ar1 model: ## {theta[i]} is m-vector of iid bernoulli trials with ## success prob pi1. ## generate observations from a ar1 model: ## x_{i}=rho * x_{i-1}+epslon_{i}+mu1*theta[i] ## in other word; if theta_{i} is 1, mean is mu1; ## otherwise mean is 0; but the ## dependence structure is like a ar1 model. ##pi1 - 0.5 ##m - 10 ##rho - 0.6 ##mu1 - 1 set.seed(66) ## generate states theta -rbinom(m, 1, pi1) ## generate data x - arima.sim(list(order=c(1,0,0), ar=rho), n=m)+mu1*theta data-list(s=theta, o=x, p=p) return(data) } [[alternative HTML version deleted]] __ 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 commented, minimal, self-contained, reproducible code.
Re: [R] generate list of variable names
Jon Erik Ween wrote: Hi! Would anyone know how to generate a list of variable names from a data frame by the class of the variable? a start... df - data.frame(f1 = factor(1:10), f2 = factor(1:10), n1 = 1:10, n2 = 1:10) sapply(df, class) I have large tables with different numbers of columns and am trying to script some rote analyses. There are several categorizing variables (factors) and many response variables (integers and numeric). I want to extract a list of classifier column names in one list and response variable names in another list, then run for-loops to calculate various statistics on the response variables in terms of the classifier variables. I thought something like this might work (but didn't): Reproducible example needed. All this can surely be done more elegantly with lapply/mapply instead of for-loops. __ 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 commented, minimal, self-contained, reproducible code.
Re: [R] comparing two regression models with different dependent variable
On Wed, Jun 9, 2010 at 5:19 PM, Or Duek ord...@gmail.com wrote: Hi, I would like to compare to regression models - each model has a different dependent variable. The first model uses a number that represents the learning curve for reward. The second model uses a number that represents the learning curve from punishment stimuli. The first model is significant and the second isn't. I want to compare those two models and show that they are significantly different. They are different, forget about significance. How can I do that? You don't. Your problem translates to whether reward or punishment gives a better learning curve, so you build a model using a factor that represents whether the learning curve comes from reward or punishment, and test the significance of the difference using the correct approach in the framework of your choice. And since curves are functions, you actually need a method for functional data analysis. Either you start eg here : http://www.psych.mcgill.ca/misc/fda/ or you take the advice of Bert. If I was you, I'd go for the latter. Thank you. You're welcome. Cheers Joris [[alternative HTML version deleted]] __ 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 commented, minimal, self-contained, reproducible code. -- Joris Meys Statistical consultant Ghent University Faculty of Bioscience Engineering Department of Applied mathematics, biometrics and process control tel : +32 9 264 59 87 joris.m...@ugent.be --- Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php __ 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 commented, minimal, self-contained, reproducible code.
[R] Calibration and validation for svycoxph
Hello, This post is for Dr. Thomas Lumley or anybody familiar with the survey package. I am estimating a proportional hazards model with weights using svycoxph. Are there functions already built in the survey package that allow me to do validation and calibration of the model? Thanks -- View this message in context: http://r.789695.n4.nabble.com/Calibration-and-validation-for-svycoxph-tp2249004p2249004.html Sent from the R help mailing list archive at Nabble.com. __ 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 commented, minimal, self-contained, reproducible code.
[R] marginal structural models
Dear listers, Does anyone have any experience running marginal structural models in r or can point me in the direction of any good tutorials on this? Regards, //M __ 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 commented, minimal, self-contained, reproducible code.
[R] for loop incremented by 0.01
Sir, I want to use a for loop which will be incremented by 0.01 in 0 to 1. Please help. Regards, Suman Dhara [[alternative HTML version deleted]] __ 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 commented, minimal, self-contained, reproducible code.
[R] passing local parameters to nls?
dear R wizards: environment-related programming question: myformula = y ~ a*x^2+b*x+c d= data.frame( x=rnorm(20), y=rnorm(20) ) cat(\nunconstrained works: \n); nls( myformula, data=d, start=list(a=1, b=1, c=1), trace= TRUE) cat(\nconstrained works: \n); b=1; nls( myformula, data=d, start=list(a=1, c=1), trace= TRUE); rm(b) cat(\nbut how do I pass a local parameter into my formula? \n); f = function(c) nls( myformula, data=d, start=list(a=1, b=1), trace= TRUE) f(c=1); advice, as always, appreciated. /iaw Ivo Welch (ivo.we...@brown.edu, ivo.we...@gmail.com) __ 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 commented, minimal, self-contained, reproducible code.
[R] creating a new variable, conditional on the value of an existing variable, selected conditionally
Dear all, I have a data frame f, with four variables: f - data.frame(A=c(0,0,1,1), B=c(0,1,0,1), C=c(1,1,0,1), D=c(3,1,2,3)) f A B C D 1 0 0 1 3 2 0 1 1 1 3 1 0 0 2 4 1 1 1 3 I want to create a new variable (f$E), such that each of its elements is drawn from either f$A, f$B, or f$C, according to the value (for each row) of f$D (values of which range from 1 to 3). In the first row, D is 3, so I want the value from the third variable (C), which for the first row is 1. In the second row, D is 1, so I want the value from the first variable (A), which for the second row is 0. And so forth, such that in the end my new data frame looks like: A B C D E 1 0 0 1 3 1 2 0 1 1 1 0 3 1 0 0 2 0 4 1 1 1 3 1 My question is: How do I do this for a much larger dataset, where my index variable (f$D in this example) actually indexes a much larger number of variables (not just three)? I know that in principle I could do this with a long series of nested ifelse statements (as below), but I assume there is some less cumbersome option, and I'd like to know what it is. Any help would be much appreciated. Apologies if I'm missing something obvious. f$E - ifelse(f$D==3, f$C, ifelse(f$D==2, f$B, f$A)) Thanks, Malcolm __ 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 commented, minimal, self-contained, reproducible code.
Re: [R] Issue with assigning text to matrix
Thanks for all your help. I found adding the 'stringsAsFactors' condition solved the problem. On 1 June 2010 17:09, Joris Meys jorism...@gmail.com wrote: Hi Jessica, this tells me that your text is saved as a factor. Try : names - read.csv(file=Names.csv,stringsAsFactors=F) Cheers Joris On Tue, Jun 1, 2010 at 11:04 AM, Jessica Queree j.j.que...@googlemail.com wrote: My issue relates to adding text to a matrix and finding that the text is converted to a number. This is the section of code I'm having trouble with: # First, I load in a list of names from a .csv file to 'names' names - read.csv(file(Names.csv)) # Then I define a matrix which will be populated with various test statistics, with several rows for each entry in names testOutput -matrix(nrow = 200, ncol = 5) for (i in 1:nrow(names)){ testOutput[i,1] - names[i,1] testOutput[i,2] - names[i,2] # test statistics code here } If I look at names[,1], I get the following: names[,1] [1] EQ_Level_UK EQ_Level_EUR EQ_Level_US EQ_Level_Far East [5] IR_PC 1_UKIR_PC 2_UKIR_PC 3_UKSwap_PC 1_UK [9] Swap_PC 2_UK Swap_PC 3_UK FX_Level_EUR FX_Level_US [13] FX_Level_Far East Infl_PC 1_UK Infl_PC 2_UK Infl_PC 3_UK [17] Prop_Level_UK CreditAAA_PC 1_UK CreditAAA_PC 2_UK CreditAAA_PC 3_UK [21] CreditAA_PC 1_UK CreditAA_PC 2_UK CreditAA_PC 3_UK CreditA_PC 1_UK [25] CreditA_PC 2_UK CreditA_PC 3_UK CreditBBB_PC 1_UK CreditBBB_PC 2_UK [29] CreditBBB_PC 3_UK 29 Levels: CreditA_PC 1_UK CreditA_PC 2_UK CreditA_PC 3_UK ... Swap_PC 3_UK But if I look at testOutput[,1], I get: testOutput[,1] [1] 15 13 16 14 23 24 25 27 28 29 17 19 18 20 21 [16] 22 26 7 8 9 4 5 6 1 2 3 10 11 12 17 [31] NA NA 19 18 NA NA NA 20 NA NA 21 NA NA 22 NA [46] NA 26 NA NA 7 NA NA 8 NA NA 9 NA NA 4 NA [61] NA 5 NA NA 6 NA NA 1 NA NA 2 NA NA 3 NA [76] NA 10 NA NA 11 NA NA 12 NA NA NA NA NA NA NA [91] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA [106] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA [121] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA [136] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA [151] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA [166] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA [181] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA [196] NA NA NA NA NA That is, the names are now converted to numbers. I think this might have something to do with the way I've defined the testOutput matrix, but haven't been able to find any information about how to fix it. Can anyone help? Many thanks. [[alternative HTML version deleted]] __ 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.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Joris Meys Statistical Consultant Ghent University Faculty of Bioscience Engineering Department of Applied mathematics, biometrics and process control Coupure Links 653 B-9000 Gent tel : +32 9 264 59 87 joris.m...@ugent.be --- Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php [[alternative HTML version deleted]] __ 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 commented, minimal, self-contained, reproducible code.
[R] Dr. Hadley Wickham - Data Visualisation in R: Harnessing the power of ggplot2. London - November 2010
Dr. Hadley Wickham - Data Visualisation in R: Harnessing the power of ggplot2 to produce elegant data graphics London: 1st - 2nd November 2010 Mango Solutions is delighted to offer a one-off 2 day training course with Dr. Hadley Wickham, R Project Data Visualisation Guru and creator of ggplot 2. The course is a must for any R user looking to improve their data visualisation skills. Suitable for any level of R experience, it will especially benefit those who know how to get data in and out of R and who can do some basic modelling. Hadley Wickham is the Dobelman Family Junior Chair in Statistics at Rice University. He is an active member of the R community, has written and contributed to over 20 R packages and won the John Chambers Award for Statistical Computing for his work developing tools for data reshaping and visualisation. His research focuses on how to make data analysis better, faster and easier with a particular emphasis on the use of visualisation to better understand data and models. Venue to be confirmed but will be a central London location. Places will be limited on what will be a very popular course. For more information please contact: train...@mango-solutions.com or visit www.mango-solutions.com Sarah Lewis T: +44 (0)1249 767700 Ext: 200 F: +44 (0)1249 767707 M: +44 (0)7746 224226 www.mango-solutions.com Unit 2 Greenways Business Park Bellinger Close Chippenham Wilts SN15 1BN UK LEGAL NOTICE This message is intended for the use o...{{dropped:9}} __ 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 commented, minimal, self-contained, reproducible code.
[R] calibration and validation for svycoxph
Hello, This post is for Dr. Thomas Lumley or anybody familiar with the survey package. I am estimating a proportional hazards model with weights using svycoxph. Are there functions already built in the survey package that allow me to do validation and calibration of the model? Thanks -- View this message in context: http://r.789695.n4.nabble.com/calibration-and-validation-for-svycoxph-tp2249118p2249118.html Sent from the R help mailing list archive at Nabble.com. __ 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 commented, minimal, self-contained, reproducible code.
Re: [R] for loop incremented by 0.01
not tested for(i in seq(0, 1, by = 0.01)) { print(i) } Read FAQ 7.31 though. suman dhara wrote: Sir, I want to use a for loop which will be incremented by 0.01 in 0 to 1. Please help. Regards, Suman Dhara [[alternative HTML version deleted]] __ 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 commented, minimal, self-contained, reproducible code. __ 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 commented, minimal, self-contained, reproducible code.
Re: [R] creating a new variable, conditional on the value of an existing variable, selected conditionally
Can your data.frame be properly coerced to a matrix like your example? If so, apply(f, 1, function(x) x[eval(x)[D]]) Malcolm Fairbrother wrote: Dear all, I have a data frame f, with four variables: f - data.frame(A=c(0,0,1,1), B=c(0,1,0,1), C=c(1,1,0,1), D=c(3,1,2,3)) f A B C D 1 0 0 1 3 2 0 1 1 1 3 1 0 0 2 4 1 1 1 3 I want to create a new variable (f$E), such that each of its elements is drawn from either f$A, f$B, or f$C, according to the value (for each row) of f$D (values of which range from 1 to 3). In the first row, D is 3, so I want the value from the third variable (C), which for the first row is 1. In the second row, D is 1, so I want the value from the first variable (A), which for the second row is 0. And so forth, such that in the end my new data frame looks like: A B C D E 1 0 0 1 3 1 2 0 1 1 1 0 3 1 0 0 2 0 4 1 1 1 3 1 My question is: How do I do this for a much larger dataset, where my index variable (f$D in this example) actually indexes a much larger number of variables (not just three)? I know that in principle I could do this with a long series of nested ifelse statements (as below), but I assume there is some less cumbersome option, and I'd like to know what it is. Any help would be much appreciated. Apologies if I'm missing something obvious. f$E - ifelse(f$D==3, f$C, ifelse(f$D==2, f$B, f$A)) Thanks, Malcolm __ 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 commented, minimal, self-contained, reproducible code. __ 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 commented, minimal, self-contained, reproducible code.
Re: [R] OOP and passing by value
Thanks to all replies. I was able to get it running with the R.oo package. I hope this reply makes it to the proper thread. Michael [[alternative HTML version deleted]] __ 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 commented, minimal, self-contained, reproducible code.
Re: [R] generate list of variable names
Thanks Erik I can't figure out how to use the various x_apply functions in this setting, nor post datasets to reproduce. But anyhow: the table structure is something like this: id (integer), handedness(R,L,A), gender(M,F), cat1(patient, control). cat2(stroke, MS, dement, control), accuracy(integer), reaction time(numeric) so, I want to extract the factor levels from cat1, cat2, etc and run, say, ANOVAs or ROCs on each of the response variables (accuracy, reaction_time, etc) extracting F-values, AUCs, etc, sticking the results in a table of results. Here is an example script I wrote for ROCR: ### library(ROCR) # Load stats package to use if not standard varslist-scan(/Users/jween/Desktop/INCAS/INCASvars.txt,list) # Read variable list results-as.data.frame(array(,c(3,length(varslist # Initialize results array, one type of stat at a time for now for (i in 1:length(varslist)){ # Loop through the variables you want to process. Determined by varslist j-noquote(varslist[i]) vars-c(varslist[i],Issue_class) # Variables to be analyzed temp-na.omit(MSsmv[vars]) # Have to subset to get rid of NA values causing ROCR to choke n-nrow(temp) # Record how many cases the analysis ios based on. Need to figure out how to calc cases/controls #.table-table(temp$SubjClass) # Maybe for later figure out cases/controls results[1,i]-j # Name particular results column results[2,i]-n # Number of subjects in analysis test-try(aucval(i,j),silent=TRUE) # Error handling in case procedure craps oust so loop can continue. Supress annoying error messages if(class(test)==try-error) next else # Run procedure only if OK, otherwise skip pred-prediction(MSsmv[[j]], MSsmv$Issue_cat); # Procedure perf-performance(pred,auc); results[3,i]-as.numeric(p...@y.values) # Enter result into appropriate row } write.table(results,/Users/jween/Desktop/IncasRres_MSsmv.csv,sep=,,col.names=FALSE,row.names=FALSE) # Write results to table rm(aucval,i,n,temp,vars,results,pred,perf,j,varslist) # Clean up test, aucval-function(i,j){ # Function to trap errors. Should be the same as real procedure above pred-prediction(MSsmv[[j]], MSsmv$Issue_cat); # Don't put any real results here, they don't seem to be passed back perf-performance(pred,auc); } ### Cheers Jon Soli Deo Gloria Jon Erik Ween, MD, MS Scientist, Kunin-Lunenfeld Applied Research Unit Director, Stroke Clinic, Brain Health Clinic, Baycrest Centre Assistant Professor, Dept. of Medicine, Div. of Neurology University of Toronto Faculty of Medicine Kimel Family Building, 6th Floor, Room 644 Baycrest Centre 3560 Bathurst Street Toronto, Ontario M6A 2E1 Canada Phone: 416-785-2500 x3648 Fax: 416-785-2484 Email: jw...@klaru-baycrest.on.ca Confidential: This communication and any attachment(s) may contain confidential or privileged information and is intended solely for the address(es) or the entity representing the recipient(s). If you have received this information in error, you are hereby advised to destroy the document and any attachment(s), make no copies of same and inform the sender immediately of the error. Any unauthorized use or disclosure of this information is strictly prohibited. On 2010-06-09, at 12:20 PM, Erik Iverson wrote: Jon Erik Ween wrote: Hi! Would anyone know how to generate a list of variable names from a data frame by the class of the variable? a start... df - data.frame(f1 = factor(1:10), f2 = factor(1:10), n1 = 1:10, n2 = 1:10) sapply(df, class) I have large tables with different numbers of columns and am trying to script some rote analyses. There are several categorizing variables (factors) and many response variables (integers and numeric). I want to extract a list of classifier column names in one list and response variable names in another list, then run for-loops to calculate various statistics on the response variables in terms of the classifier variables. I thought something like this might work (but didn't): Reproducible example needed. All this can surely be done more elegantly with lapply/mapply instead of for-loops. __ 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 commented, minimal, self-contained, reproducible code.
Re: [R] How to add a new plot in the same graph using add=T at the command plot?
Soapbox: Well, if you're just starting out with R it would be a VERY good idea to learn right away that T is not TRUE and F is not FALSE, at least not always. Sooner or later you WILL have problems. So do yourself a favour and get into the habit of using TRUE/FALSE instead of T/F. (I know that Petr knows better.) -Peter Ehlers On 2010-06-09 9:08, Larissa Lucena wrote: Thanks so much!!! I'm using R for the first time, and so, I have many stupid doubts! Sorry and thanks again! Regards! 2010/6/9 Petr PIKALpetr.pi...@precheza.cz Hi where did you find parameter add=T. You can use par(new=T) before using new plot command or use points, lines Regards Petr __ 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 commented, minimal, self-contained, reproducible code.
Re: [R] dealing with heteroscedasticity in lmer: problem with the method weights
doris gomez dodogomez at yahoo.fr writes: Dear lmer users, You should probably redirect this sort of question to r-sig-mixed-mod...@r-project.org , rather than the generic R help list. The experiment includes 15 groups of (3 males and 1 female). The female is characterized by its quality Q1 and Q2. Each male of a group is characterized by the number of MatingAttempts (with Poisson distribution). I want to examine if male mating attempts depend on female quality. I can see from graphic exploration that the within-group heterogeneity of male attempts increases with female quality Q1. Is this true above and beyond the expected increase in variance due to the Poisson distribution of the data? When including the method weights in the function lmer, I get the message that variables' length varies and the model does not run. lmer(MatingAttempts~Q1+Q2+(1|Group),data=file, family=poisson,na.action=na.omit, REML=FALSE, weights=varExp(form=~Q1)) The REML and weights arguments do not make sense in the context of a GLMM fitted with [g]lmer. If I run the same model (fixed effects and random effects) with lme, it works properly, which shows that there is no problem with data structure. lme(MatingAttempts~Q1+Q2,random=~1|Group, data=file,na.action=na.omit, method=ML, weights=varExp(form=~Q1)) As you presumably know, this model does not incorporate the Poisson distribution of the data. I saw on the forum that lmer had problems in taking into account variance heterogeneity. Yet, the messages were old and there are maybe new solutions. How can I correct the analyses for this problem of heteroscedasticity? Should I normalise the within group variance before implementing the model? And deal with the variance (as a new variable to explain) in another model? Is there another way to solve this problem? (1) lmer still does not allow for models of heteroscedasticity as implemented in the weights() argument of lme, and may not for some time ... (2) You _could_ use glmmPQL() from the MASS package, along the lines of MASS::glmmPQL(MatingAttempts~Q1+Q2,random=~1|Group, family=poisson, data=file,na.action=na.omit, weights=varExp(form=~Q1)) **HOWEVER**: it's not entirely clear what statistical model this represents, or whether it makes sense. (3) I would recommend fitting the GLMM, with lmer, without the heteroscedasticity, and then see whether the heteroscedasticity remains in the Pearson residuals or not ... (don't forget to check for overdispersion too). __ 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 commented, minimal, self-contained, reproducible code.
Re: [R] how to draw the probability ellipse circle figure?
Jie TANG totangjie at gmail.com writes: hi ,R user folks . Nowadays I read a paper which draw a probability ellipse circle figure shown in the appendix. I wonder how to draw this figure by R ? the x-axis and y-axis both express the error but in different direction . Your question is quite vague, but perhaps you might start with the ellipse package. Also try RSiteSearch(ellipse) __ 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 commented, minimal, self-contained, reproducible code.
[R] cut edge from surface using persp()
Hi R users! Is it possible to cut the edges from a surface graph without to cut the axes using persp function? I am using the following code: op - par(bg = white) persp(phi1, phi2, z,main=Bullwhip generated with AR(2) demand when L=1, xlab =phi1 , ylab =phi2, zlab =Bullwhip, theta = 30, phi = 20, r=50,d=0.1,expand=0.5,ltheta=90,border = NA, lphi=180, shade=0.75, ticktype=detailed,nticks=5) when I put box=FALSE the axes just disappear. Any help will be appreciated. Marlene. [[alternative HTML version deleted]] __ 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 commented, minimal, self-contained, reproducible code.
Re: [R] passing local parameters to nls?
It looks in the environment of your formula (which in this case is the global environment) and then in data. Thus here are two solutions: f2 - function(c) { environment(fo) - environment() nls(fo, data=d, start=list(a=1, b=1)) } f3 - function(c) nls(fo, data=c(d, c = c), start=list(a=1, b=1)) fo - y ~ a + x^2 + b * x + c f2(1) f3(1) On Wed, Jun 9, 2010 at 9:39 AM, ivo welch ivo...@gmail.com wrote: dear R wizards: environment-related programming question: myformula = y ~ a*x^2+b*x+c d= data.frame( x=rnorm(20), y=rnorm(20) ) cat(\nunconstrained works: \n); nls( myformula, data=d, start=list(a=1, b=1, c=1), trace= TRUE) cat(\nconstrained works: \n); b=1; nls( myformula, data=d, start=list(a=1, c=1), trace= TRUE); rm(b) cat(\nbut how do I pass a local parameter into my formula? \n); f = function(c) nls( myformula, data=d, start=list(a=1, b=1), trace= TRUE) f(c=1); advice, as always, appreciated. /iaw Ivo Welch (ivo.we...@brown.edu, ivo.we...@gmail.com) __ 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 commented, minimal, self-contained, reproducible code. __ 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 commented, minimal, self-contained, reproducible code.
Re: [R] combining expressions in mathplot
Uwe, Very nice, thank you. Rich [[alternative HTML version deleted]] __ 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 commented, minimal, self-contained, reproducible code.
Re: [R] Rglpk
On 2010-06-09 5:11, Kaveh Vakili wrote: Hi list, in the Rglpk_solve_LP function (::Rglpk), on line 26, the function calls a function as.glp_bounds() that i cannot access. i'm trying to alter the Rglpk_solve_LP function to add a line to retrieve column/row dual values. everytime i change the slightest line of code inside Rglpk_solve_LP() [to even add a print] i get a ': could not find function as.glp_bounds' What's the catch here ? No catch: as.glp_bounds() is buried in namespace:Rglpk. Your modified function is presumably in the global environment. This should work: Let's say your modified function is myfun(). After you source myfun, set its environment with environment(myfun) - environment(Rglpk_solve_LP) -Peter Ehlers __ 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 commented, minimal, self-contained, reproducible code.
Re: [R] for loop incremented by 0.01
Why? See ?seq seq(0,1,.01) --- On Wed, 6/9/10, suman dhara suman.dhar...@gmail.com wrote: From: suman dhara suman.dhar...@gmail.com Subject: [R] for loop incremented by 0.01 To: r-h...@stat.math.ethz.ch Received: Wednesday, June 9, 2010, 12:30 PM Sir, I want to use a for loop which will be incremented by 0.01 in 0 to 1. Please help. Regards, Suman Dhara [[alternative HTML version deleted]] __ 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 commented, minimal, self-contained, reproducible code. __ 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 commented, minimal, self-contained, reproducible code.
Re: [R] How to add a new plot in the same graph using add=T at the command plot?
I've really apreciated your advice! Thanks! On Wed, Jun 9, 2010 at 14:05, Peter Ehlers ehl...@ucalgary.ca wrote: Soapbox: Well, if you're just starting out with R it would be a VERY good idea to learn right away that T is not TRUE and F is not FALSE, at least not always. Sooner or later you WILL have problems. So do yourself a favour and get into the habit of using TRUE/FALSE instead of T/F. (I know that Petr knows better.) -Peter Ehlers On 2010-06-09 9:08, Larissa Lucena wrote: Thanks so much!!! I'm using R for the first time, and so, I have many stupid doubts! Sorry and thanks again! Regards! 2010/6/9 Petr PIKALpetr.pi...@precheza.cz Hi where did you find parameter add=T. You can use par(new=T) before using new plot command or use points, lines Regards Petr -- Larissa [[alternative HTML version deleted]] __ 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 commented, minimal, self-contained, reproducible code.