[R] Online, automatic evaluation of class assessment R scripts
Dear R group, I will be giving a course on R in a bit of time. I am very intrigued by the way R coding assessments are done in several courses on Coursera and would like to figure out whether I am capable of setting up such a system for my course. On Coursera, R scripts are submitted online and then directly evaluated so that students see the outcome and resubmit if necessary. Is there anyone who is willing to share his / her experience with setting up the corresponding environment (on a server) and writing the scripts? Or point me to helpful information? I am sorry if the answer is indeed already on the web but I might not have found the right search terms. At least I was not able to find anything about this. Thanks a million, Werner [[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 new(er) R version's matrix package
Dear Martin, Arne, David, Thanks for considering my problem. However, I have a bit of a problem in making a small reproducible example. So far, I tried to drill down into the code and to quick fix this by setting the particular tolerance to zero which switches off the check in .solve.sparse.dgC. The obstacle I got stuck with doing that is, seemingly, the solvetol parameter from systemfit.control is not handed through all the way. .calcGLS from systemfit still hands it over but it does not reach .solve.sparse.dgC This is the stack at that point before the error is thrown: Browse[2] where where 1: .solve.sparse.dgC(as(a, dgCMatrix), b = b, tol = tol) where 2: solve.dsC.dC(a, b) where 3: solve(a, as(b, CsparseMatrix)) where 4: solve(a, as(b, CsparseMatrix)) where 5: eval(expr, envir, enclos) where 6: eval(call, sys.frame(sys.parent())) where 7: callGeneric(a, as(b, CsparseMatrix)) where 8: solve(forceCspSymmetric(a, isTri = FALSE), b = Diagonal(nrow(a))) where 9: solve(forceCspSymmetric(a, isTri = FALSE), b = Diagonal(nrow(a))) where 10: .local(a, b, ...) where 11: solve(W, tol = solvetol) where 12: solve(W, tol = solvetol) where 13: as.matrix(solve(W, tol = solvetol)[1:ncol(xMat), 1:ncol(xMat)]) where 14: .calcGLS(xMat = xMatAll, R.restr = R.restr, q.restr = q.restr, sigma = rcov, validObsEq = validObsEq, useMatrix = control$useMatrix, solvetol = control$solvetol) where 15 at ILLS.R#465: systemfit(eqsys, method = SUR, data = dat, restrict.matrix = restrmat, control = sysfit.contr) I will now further try to create a small, reproducible example. I also have to better understand what the procedure is doing to be able to decide whether the previous results were wrong or this newly occurring error is wrong. Many thanks, Werner Martin Maechler maech...@stat.math.ethz.ch schrieb am 22:00 Samstag, 26.April 2014: Arne Henningsen arne.henning...@gmail.com on Sat, 26 Apr 2014 08:15:37 +0200 writes: On 25 April 2014 20:15, David Winsemius dwinsem...@comcast.net wrote: On Apr 25, 2014, at 9:17 AM, Werner W. wrote: Dear Rs, I am re-executing some older code. It does work in the ancient R 2.12.0 which I still have on my PC but with the new version R 3.1.0 it does not work any more (but some other new stuff, which won't work with 2.12). The problem arises in context with the systemfit package using the matrix package. In R 3.1.0 the following error is thrown: Error in as.matrix(solve(W, tol = solvetol)[1:ncol(xMat), 1:ncol(xMat)]) : error in evaluating the argument 'x' in selecting a method for function 'as.matrix': Error in .solve.sparse.dgC(as(a, dgCMatrix), b = b, tol = tol) : LU computationally singular: ratio of extreme entries in |diag(U)| = 7.012e-39 However, I have no clue what I can do about this. Was there some change in the defaults of the matrix package? I couldn't find anything apparent in the changelog. As the same code works in R 2.12.0, I suppose that the problem is not my data. You have not told us what version of the Matrix package you were using. As such I would suggest that you review the Changelog which is a link for the CRAN page for pkg:Matrix and go back 4 years or so since R major versions change about once a year. http://cran.r-project.org/web/packages/Matrix/ChangeLog In addition, please provide a minimal, self-contained, reproducible example. Yes, please do. As maintainer of the Matrix package, I'm willing to look into the situation of course. As was mentioned, many things have changed in 4 years. The error message above looks like you'd want to invert a (very close to) singular matrix, and there could be quite few reasons why parts of the older code gave slightly different answers. Without a reproducible example, we can't get started though. Best regards, Martin Maechler, ETH Zurich [[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 with new(er) R version's matrix package
Dear Rs, I am re-executing some older code. It does work in the ancient R 2.12.0 which I still have on my PC but with the new version R 3.1.0 it does not work any more (but some other new stuff, which won't work with 2.12). The problem arises in context with the systemfit package using the matrix package. In R 3.1.0 the following error is thrown: Error in as.matrix(solve(W, tol = solvetol)[1:ncol(xMat), 1:ncol(xMat)]) : error in evaluating the argument 'x' in selecting a method for function 'as.matrix': Error in .solve.sparse.dgC(as(a, dgCMatrix), b = b, tol = tol) : LU computationally singular: ratio of extreme entries in |diag(U)| = 7.012e-39 However, I have no clue what I can do about this. Was there some change in the defaults of the matrix package? I couldn't find anything apparent in the changelog. As the same code works in R 2.12.0, I suppose that the problem is not my data. If anyone has an idea about this, I would really appreciate your hints. Thanks! Werner [[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] R book or other materials for teaching a one week class on data analysis
Dear Rusers, I am starting to develop a one week course in which I want to cover an R programming introduction and go over data analysis / statistics / econometrics incl. visualization and maybe reproducible research as an extra. The goal is to give research students a kick start with R so that they can use it productively for their thesis work and add or refresh some statistics / analysis / econometrics skills. I have collected some materials from the web etc. which will be helpful but it probably would be good to have one main book or other reference which the students can hold on to as a reference or guideline over the course. Would anyone have a good suggestion what book to use or even experience with using one in a similar course? Thank you very much for any ideas! Werner __ 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] Simple Likert count data visualization
Hello, Before I start to construct something inferior myself I would like to know if such a plot function is already out there. I have count data of a small survey with a few questions which use a scale from Strongly disagree to Strongly agree and similar things. What I would like to have for a slide is a plot which shows for each question a line over this scale and the put a few markers on for the mode and mean or so. A graph which I think should also be accessible to almost everybody. Does such a plot function exist? If not, is there something similar which I could abuse for this purpose? Many thanks for considering my query. Werner __ 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] Print to console from within Sweave script
Hi, is it possible to send some message to the console from within a .Rnw Sweave script, ie. when executing Sweave()? The background is that only in particular circumstances my script is doing some lengthy computations and I would like to print some status information to the console. It seems Sweave redirects all output though. Any suggestions? Thanks a lot for considering my question. All the best Werner __ 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] function which can apply a function by a grouping variable and also hand over an additional variable, e.g. a weight
Hi, I was wondering if there is an easy way to accomplish the following in R: Often I want to apply a function, e.g. weighted.quantile from the Hmisc package to grouped subsets of a data.frame (grouping variable) but then I also need to hand over the weights which seems not possible with summaryBy or aggregate or the like. Is there a function to do this? Currently I do this with loops but it is very slow. I would be very grateful for any hints. Thanks, Werner __ 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 comment out entire code parts in Sweave files
Hi, I am wondering if there is any convenient way to comment out an entire region of a Sweave file which comprises R and Latex code. Currently I'm doing it for the R and Latex parts separately or transfer the unwanted part into a different file. But both are not great solutions. (I am doing this when updating old files and debugging) Is there a way to do this with an equivalent of \iffalse \fi or is there some stop command after which Sweave just stops processing? Thanks a lot for any suggestions. Werner __ 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] data.frame: return all rows where at least one...
Hi, I know ways to do this but they all seem awkward and I somehow believe that there is a convenient shortcut. If I have a data.frame with many columns, how can I request all rows for which at least one column satisfy an expression? For instance, all rows where at least one column is negative. Many thanks, Werner __ 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] data.frame: return all rows where at least one...
Thanks for the answers! The any function was basically exactly what I was looking for. (previously I used something with rowSums() which is probably not the most efficient way.) Thanks so much, Werner -- View this message in context: http://r.789695.n4.nabble.com/data-frame-return-all-rows-where-at-least-one-tp2316292p2316407.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] how can I look at .Internal(model.matrix(t, data))?
Hi, I would like to see how model.matrix expands factor column to a set of dummy columns. I think that is done int .Internal(model.matrix(t, data)) which is called from model.matrix.default. But I have not idea how I can look at this function. How can I get to such internal functions? Thanks so much! Werner einen herausragenden Schutz gegen Massenmails. http://mail.yahoo.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] Once again: Error: cannot allocate vector of size
Thanks Matthew, you are absolutely right. I am working on Windows XP SP2 32bit with R versions 2.9.1. Here is an example: d - as.data.frame(matrix(trunc(rnorm(6*27136, 1, 100)),ncol=6)) d[,4:5] - trunc(100*runif(2*27136, 0, 1)) d[,6] - trunc(1000*runif(27136, 0, 1)) for (i in 4:6) d[,i] - as.factor(d[,i]) lm(V1 ~ log(V2) + log(V3) + V4 + V5 + V6, data=d) memory.size(max=F) memory.size(max=T) I managed to get it run through after setting the 3GB switch for Windows and with a clean R session. I also noticed later, that after removing na.action=na.exclude more regressions run through. But before and after the lm() it seems there should be enough memory which means that lm() builds up some quite large objects during its computations? -- View this message in context: http://n4.nabble.com/Once-again-Error-cannot-allocate-vector-of-size-tp1083506p1100164.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] Once again: Error: cannot allocate vector of size
Hi, I have browsed the help list and looked at the FAQ but I don't find conclusive evidence if this is normal or I am doing something wrong. I am running a lm() on a data.frame with 27136 observations of 6 variables (3 num and 3 factor). After a while R throws this: lm(log(y) ~ log(a) + log(b) + c + d + e, data=reg.data , na.action=na.exclude) Error: cannot allocate vector of size 203.7 MB This is a Windows XP 32 bit machine with 4 GB in it so that theoretically, R should be able to claim close to 2 GB. This is the gc() after the regression: used (Mb) gc trigger (Mb) max used (Mb) Ncells 272299 7.3 875833 23.4 1368491 36.6 Vcells 4526037 34.6 116536251 889.2 145524997 1110.3 memory.size(max=T) [1] 1230.25 memory.size(max=F) [1] 47.89 Looking at memory.size, R should be easily able to allocate that space, shouldn't it? Many thanks for any hints! --Werner __ Do You Yahoo!? Sie si n Massenmails. http://mail.yahoo.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] Remove term from formula for predict.lm
Hi, probably just a quick question: can I somehow change the formula used with predict? E.g., the regression was run on y ~ u + v + w but for the prediction the term v should be removed from the formula contained in the regression object and only y ~ u + w be used. I could use model.matrix etc. to do the predictions but it would be very helpful to know a simpler way. Thanks so much, Werner __ verfügt über einen herausragenden Schutz gegen Massenmails. http://mail.yahoo.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] Remove term from formula for predict.lm
Thanks Gabor and Henrique! Sorry for the imprecise question. I want predict() to use the coefficients estimated by the original regression but to exclude terms from the prediction formula. If I originally estimated y ~ x1 + x2 and got coefficients b0, b1, b2, I would like to remove x2 and predict y = b0 + b1*x1 using the the originally estimated coefficients b0 and b1. @Gabor: I tried your suggestion but it seems although predict now accepts a list with fewer variables, the new function is not used so that the coefficient does not change. mod - lm(y1 ~ x1 + x2 + x3 + x4, anscombe) predict(eval(mod$call), list(x1=1,x2=1,x3=1, x4=1)) 1 4.684909 Warning message: In predict.lm(eval(mod$call), list(x1 = 1, x2 = 1, x3 = 1, x4 = 1)) : prediction from a rank-deficient fit may be misleading mod$call$formula - update(as.formula(mod$call$formula), ~ . - x1 - x2) predict(eval(mod$call), list(x3=1, x4=1)) 1 4.684909 Many thanks, Werner -- View this message in context: http://n4.nabble.com/Remove-term-from-formula-for-predict-lm-tp1017686p1017749.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] Remove term from formula for predict.lm
Thanks a lot for the answers! Somehow I thought there will be a facility to modify the formula. But setting unwanted variables to zero will of course work and maybe is simple enough. Thanks again! -- View this message in context: http://n4.nabble.com/Remove-term-from-formula-for-predict-lm-tp1017686p1017919.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] Functions for QUAIDS and nonlinear SUR?
Hi, I would like to estimate a quadratic almost ideal demand system in R which is estimated usually by nonlinear seemingly unrelated regression. But there is no such function in R yet but it is readily available in STATA (nlsur), see B. Poi (2008): Demand-system estimation: Update, Stata Journal 8(4). Now I am thinking, what is quicker learning to program STATA which seems not really comfortable for programming or implement the method in R which might be above my head in terms of econometrics. May be it works with nlsystemfit? Has anyone recommendations how to proceed or any pointers to a somewhat sure way to go in R? Thanks so much, Werner __ Do You Yahoo!? hutz gegen Massenmails. http://mail.yahoo.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] Viewing function code
Hi, in the quest of learning from others' codes, I am still stumbling over the problem how to view some of the functions. I know about methods() getAnywhere(), showMethods(), getMethods() but I still cannot view every function. How would I look at the code of the merge function? Thanks a million, Werner -- View this message in context: http://www.nabble.com/Viewing-function-code-tp24895753p24895753.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] Viewing function code
Brilliant, that works! Thanks a lot for the quick help, Werner Dimitris Rizopoulos-4 wrote: well, you almost have it -- try this: # two methods for the merge generic methods(merge) merge.default merge.data.frame I hope it helps. Best, Dimitris -- View this message in context: http://www.nabble.com/Viewing-function-code-tp24895753p24895956.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] solving system of equations involving non-linearities
Many thanks, BBsolve works like a charm. First I thought I should use the squares of the equations because BBsolve would use some minimization objective function anyway but it actually only works if I don't use the squared equations. I'll check the documentation if I find something about the objective. Thanks for the help, Werner Ravi Varadhan wrote: You have two options: 1. The `BBsolve' function in the BB package to solve this system of 3 equations. 2. Try `nleqslv' function in the nleqslv package. These would work even if the residual is not zero. Hope this helps, Ravi. -- View this message in context: http://www.nabble.com/solving-system-of-equations-involving-non-linearities-tp24845136p24859703.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] portable R editor
Unfortunately, the suggested way with JauntePE does not work completely. Maybe I have found a better alternative now: There is a little free application by Sysinternals (now owned by MS) which can create junction points, i.e. a system link to a directory under Windows. It is available here: http://technet.microsoft.com/en-us/sysinternals/bb896768.aspx In my setup, I have under the root directory of the USB stick one dir called Programs and one called Application Data. I have copied the Tinn-R folder to Programs and the ini files from the user profile into Application Data. In Programs\Tinn-R I have created a batch file startTinn-R.bat with this content: REM START junction %APPDATA%\Tinn-R %CD%\..\..\..\Application Data\Tinn-R @start .\bin\Tinn-R REM END and copied the junction.exe into this dir as well. When I double click this bat file, a link to the ini files on the USB stick is created in the user's application data directory in the local harddrive of the PC used. But note that this does not work if there exists a Tinn-R directory already in the user's application data dir in local harddrive. All the best, Werner Werner W. wrote: JauntePE is really easy to use. It does not take any particular skill. Just launch the main application, click on the Lauch JPE Quickie Button and it will guide you through the process. I left everything with the default settings. In brief, one starts the Tinn-R installer once from within JPE probably to check which folders, files, and registry entries are generated. Then, again from within JPE, one starts the now on the portable media installed Tinn-R application and finally the entire application can be packaged up which probably generates the starter and virtualization files within the Tinn-R folder. I realized that startup of Tinn-R is now slower and I haven't worked with that installation seriously yet but everything seems all right so far. Regards, Werner -- View this message in context: http://www.nabble.com/portable-R-editor-tp22291017p22484751.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] portable R editor
JauntePE is really easy to use. It does not take any particular skill. Just launch the main application, click on the Lauch JPE Quickie Button and it will guide you through the process. I left everything with the default settings. In brief, one starts the Tinn-R installer once from within JPE probably to check which folders, files, and registry entries are generated. Then, again from within JPE, one starts the now on the portable media installed Tinn-R application and finally the entire application can be packaged up which probably generates the starter and virtualization files within the Tinn-R folder. I realized that startup of Tinn-R is now slower and I haven't worked with that installation seriously yet but everything seems all right so far. Regards, Werner jcfaria wrote: Could you to post here details about the Tinn-R truly portable with JauntePE? I think it will be also useful for all Tinn-R users, like me. ;-) Many thanks, JCFaria -- View this message in context: http://www.nabble.com/portable-R-editor-tp22291017p22352524.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] portable R editor
Many, many thanks for all the answers! Notepad++ looks very promising although it does not have a project file management facility. But it has a very clean appearance. I'll have to look into SciTE which also sounds quite good. There seem to be some good alternatives. Meanwhile, I found a freeware application which helps to make Tinn-R truly portable: JauntePE (http://www.portablefreeware.com/?id=1452) virtualizes access to the registry and file system and can easily be used to make also the ini settings portable. Thus, everything will be on the USB stick. Thanks again, Werner -- View this message in context: http://www.nabble.com/portable-R-editor-tp22291017p22328322.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.