tag:blogger.com,1999:blog-1816488797213954066.post6734226580861624113..comments2023-10-17T05:43:46.740-04:00Comments on eKonometrics: R: simple for complex tasks, complex for simple tasksMurtaza Haiderhttp://www.blogger.com/profile/11315309304368143831noreply@blogger.comBlogger6125tag:blogger.com,1999:blog-1816488797213954066.post-29690684596709346002018-03-12T12:46:31.051-04:002018-03-12T12:46:31.051-04:00So there have been some comments about GUI-based o...So there have been some comments about GUI-based options, and I'd plug one for radiant: http://vnijs.github.io/radiant/. I would also say tableone takes a shot at this as well: https://cran.r-project.org/web/packages/tableone/vignettes/introduction.htmlAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-1816488797213954066.post-49816750922495769252018-03-12T02:25:13.150-04:002018-03-12T02:25:13.150-04:00Greetings,
Thank you for your suggestions. Also, ...Greetings,<br /><br />Thank you for your suggestions. Also, I noted that I used the "with" command unnecessarily in the text. The following syntax works without the "with" option.<br /><br />mean.cars <- sapply(mtcars[c("mpg", "disp", "hp")], mean)<br />sd.cars <- sapply(mtcars[c("mpg", "disp", "hp")], sd)<br />n.cars <- sapply(mtcars[c("mpg", "disp", "hp")], length)<br /><br />cbind(n.cars, mean.cars, sd.cars)<br />round(cbind(n.cars, mean.cars, sd.cars),2)<br /><br />round(t(sapply(mtcars[c("mpg", "disp", "hp")], <br /> function(x) c(n=length(x), avg=mean(x), stdev=sd(x)))), 2)<br /><br />Sincerely, MurtazaMurtaza Haiderhttps://www.blogger.com/profile/11315309304368143831noreply@blogger.comtag:blogger.com,1999:blog-1816488797213954066.post-78675869769782142262018-03-12T01:18:07.781-04:002018-03-12T01:18:07.781-04:00Consider the following approach and whether you ag...Consider the following approach and whether you agree that my description of teaching it is within the ability of undergraduates to grasp.<br /><br />library(dplyr) # part of the tidyverse package/ecosystem to streamline processing<br />data(mtcars) # even built-in data still has to be loaded explicitly<br />fs <- c("mean", "sd") # create a vector of functions to be applied<br /><br /># select from mtcars the three columns of interest, pipe them to be summarized (collapsed into<br /># a single row) consisting of the mean and standard deviation of each column then<br /># pipe to be rounded to three places and finally add a new column for the number of observations<br /># ASSUMED to be equal to the number of rows in the data frame; in the real world you have to<br /># deal with missing data. With only 32 rows, we can confirm the lack of NAs by visual inspection<br /><br />select(mtcars, mpg, disp, hp) %>% summarize_all(funs_(fs)) %>% mutate_all(round, 3) %>% mutate(n = nrow(mtcars))<br /><br />I appreciate that in the context of an undergraduate course in business analysis, you shouldn't have to devote a substantial amount of time teaching R. (However, a prospective statistics major who can't master R should consider an alternative career.)<br /><br />What I'd suggest is to orient students to R by describing it a tool to solve alegbraic equations. They had to have grasped f(x) = y to make it to your classroom in the first place.<br /><br />In this example,<br /><br />1. They are going to be using functions provided by a contributed R package.<br />2. They need to know how to install the package if they get a not-found error<br />3. They need to know ls() to begin developing a notion of namespace, so if they are trying to do something with mtcars and it's a not found object, they can see for themselves that it's not there and they need to do something, which is to use the data function. Eventually, they will need to learn how to read in their own data.<br />4. They need to know that <- and = are assignment operators that give a name some property<br />5. c means combine into a vector<br />6. A vector is a list of objects, analogous to either a row or a column of a spreadsheet<br />7. The quotation marks within c are to use the *names* of the functions, not the functions themselves. Otherwise, there's no way of knowing the mean of what?<br />8. select is a function from dplyr; it's arguments are the name of the object, the mtcars data frame, the columns or variables to be pulled out.<br />9. %>% is a pipe that passes on the results from the left to the right<br />10. summarize_all takes the result, a trimmed down data frame, and applies a function<br />11. The function it applies is funs_, another dyplr feature that applies the functions in the vector fs to the trimmed down data frame.<br />12. Another %>% sends the result downstream to be rounded<br />13. Last is to add a column for n<br /><br />With that as an example, it's easy to drill.<br /><br />Redefine fs to obtain the minimum, maximum and median of mtcars, for mpg, disp and hp<br /><br />fs <- c("min", "max", "median")<br /><br />Do you need to make any changes to <br /><br />select(mtcars, mpg, disp, hp) %>% summarize_all(funs_(fs)) %>% mutate_all(round, 3) %>% mutate(n = nrow(mtcars))<br /><br />to get the new result?<br /><br />What would you do to get quantiles and IQR, the interquantile range?<br /><br />For statistics majors, get them out of cut and paste and into RMarkdown as soon as possible.Anonymoushttps://www.blogger.com/profile/14252478855274959323noreply@blogger.comtag:blogger.com,1999:blog-1816488797213954066.post-70252015452717220822018-03-12T01:01:11.151-04:002018-03-12T01:01:11.151-04:00library(tidyverse)
mtcars %>%
select(mpg, di...library(tidyverse)<br />mtcars %>% <br /> select(mpg, disp, hp) %>% <br /> sapply(function(x) c(n = length(x), mu = mean(x), sigma = sd(x))) %>%<br /> t %>% <br /> round(2)<br /><br /> n mu sigma<br />mpg 32 20.09 6.03<br />disp 32 230.72 123.94<br />hp 32 146.69 68.56<br /><br />#################### now without the tidyverse<br /><br />mat <- sapply(subset(mtcars, select = c(mpg, disp, hp)),<br /> function(x) c(n = length(x), mu = mean(x), sigma = sd(x)))<br />mat <- round(t(mat), 2)<br />mat<br /> n mu sigma<br />mpg 32 20.09 6.03<br />disp 32 230.72 123.94<br />hp 32 146.69 68.56<br /><br />############ where's the problem?Bill Venableshttps://www.blogger.com/profile/17388811817434387510noreply@blogger.comtag:blogger.com,1999:blog-1816488797213954066.post-68145076023853624032018-03-11T16:54:58.443-04:002018-03-11T16:54:58.443-04:00You might want to take a look at Jmovi (https://ww...You might want to take a look at Jmovi (https://www.jamovi.org/).<br /><br />It's point-and-click but reproducible, and based on R.<br /><br />We're starting to use it for researchers who want to do some of their own analysis. I'm thinking it would work for undergrad/MBA students where your goal isn't to teach them R, but for them to understand the analysis/stats concepts.Petehttps://www.blogger.com/profile/13575845320239157429noreply@blogger.comtag:blogger.com,1999:blog-1816488797213954066.post-73164909261054368062018-03-11T04:10:47.510-04:002018-03-11T04:10:47.510-04:00I agree, for a quite large part. I think, however,...I agree, for a quite large part. I think, however, tidyverse makes the simple things at least a little simpler. The task performed above then becomes<br /><b>mtcars %>%<br /> select(mpg, disp, hp) %>%<br /> gather("Variable", "Value", mpg, disp, hp) %>%<br /> group_by(Variable) %>%<br /> summarise_all(funs(length, mean, sd, min, max))</b><br />It still requires the student to learn quite a few things, so perhaps even more useful is to just tell the students that with R, a little bit of googling is part of the work flow. Also, tell the students that https://www.statmethods.net/index.html is a very good resource (which in this case quickly points you to Hmisc::describe, pastecs::stat.desc as well as psych::describe that you mention yourself).Daghttps://www.blogger.com/profile/10101621423847235283noreply@blogger.com