{"id":3037,"date":"2015-04-02T11:43:20","date_gmt":"2015-04-02T16:43:20","guid":{"rendered":"http:\/\/www.ssc.wisc.edu\/~jfrees\/?page_id=3037"},"modified":"2023-06-08T14:46:24","modified_gmt":"2023-06-08T19:46:24","slug":"active-learning-and-r","status":"publish","type":"page","link":"https:\/\/users.ssc.wisc.edu\/~ewfrees\/regression\/active-learning-and-r\/","title":{"rendered":"Active Learning and R"},"content":{"rendered":"<p>I hope that you find this site useful while commuting to work or school or in quiet times while sitting on an easy chair thinking deep thoughts. Personally, I find that these are times when a book (hard-copy or electronic) is more suitable for my learning style. But, to each their own.<\/p>\n<p><strong>Active Learning<\/strong><br \/>\nFor other times, this site is designed for people to be <em>actively<\/em> engaged in learning statistical methods. Although one can make great strides in learning statistical theory in non-active modes while reading a textbook, I believe that the process of applying these theories to data can only be learned by doing. So, be an active participant; spend some time thinking about each situation I propose before viewing the solutions. Then, when you have seen the solution, play a &#8220;what if?&#8221; game. See what would happen if you tweak the model a bit or use another data set. Remember, in this environment, you are both the learner and the teacher.<\/p>\n<p>To allow you to be an active participant, this site features the statistical package <span style=\"font-family: 'American Typewriter'\">R<\/span> as a tool for analyzing data. They are many great statistical packages available, all with relative strengths and weaknesses. My approach to learning statistical methods is that if you understand the theory and are familiar with one package, learning a second package is relatively straight-forward. (Easy for me to say&#8230;.). <\/p>\n<p>To get you started on <span style=\"font-family: 'American   Typewriter'\">R<\/span>, I have some installation and starting instructions on my companion site, available <a style=\"font-size: 14px\" href=\"http:\/\/instruction.bus.wisc.edu\/jfrees\/jfreesbooks\/Regression%20Modeling\/BookWebDec2010\/installR.html\" target=\"_blank\" rel=\"noopener\">here<\/a>. This statistical package is widely (and freely) available, so there are lots of great places that also provide this support. The original source site is <a style=\"font-size: 14px\" href=\"http:\/\/www.r-project.org\" target=\"_blank\" rel=\"noopener\">www.r-project.org<\/a>.<\/p>\n<p><strong>Site Conventions for Including <span style=\"font-family: 'American   Typewriter'\">R<\/span> Code<\/strong><br \/>\nin this site you will see that I have included examples where I say things like &#8220;See R Code in Action&#8221;. When you click on this, it displays the <span style=\"font-family: 'American   Typewriter'\">R code<\/span> and a little button that says &#8220;Evaluate&#8221;. If you do so, it sends the <span style=\"font-family: 'American   Typewriter'\">R<\/span> code off to a server someplace, evaluates the <span style=\"font-family: 'American   Typewriter'\">R<\/span> code, and sends the output back! This is very cool because it means that you don&#8217;t have to install <span style=\"font-family: 'American   Typewriter'\">R<\/span> to run the demo. You can also alter the commands and explore on your own. Give it a try.<\/p>\n<h2 style=\"text-align: center;\"><a id=\"displayTextf8.3\" href=\"javascript:togglecode('toggleTextf8.3','displayTextf8.3');\"><i><strong>See R Code in Action<\/strong><\/i><\/a><\/h2>\n<div class=\"sage-r\" id=\"toggleTextf8.3\" style=\"display: block\"><script type=\"text\/x-sage\">\n\r\n#  THIS CODE USES THE DATASET TERMLIFE.CSV\r\nTerm <- read.table(file=\"http:\/\/instruction.bus.wisc.edu\/jfrees\/jfreesbooks\/Regression%20Modeling\/BookWebDec2010\/CSVData\/TermLife.csv\", header=TRUE, sep=\",\")\r\n\r\n#  PICK THE SUBSET OF THE DATA CORRESPONDING TO TERM PURCHASE\r\nTerm2 <- subset(Term, subset=FACE > 0)\r\nTerm2$LNFACE <- with(Term2, log(FACE))\r\nTerm2$LNINCOME <- with (Term2, log(INCOME))\r\n\r\nXymat <- data.frame(Term2$FACE, Term2$INCOME, Term2$EDUCATION, Term2$NUMHH, Term2$LNFACE, Term2$LNINCOME)\r\nmeanSummary <- sapply(Xymat, mean,  na.rm=TRUE)\r\nsdSummary   <- sapply(Xymat, sd,    na.rm=TRUE)\r\nminSummary  <- sapply(Xymat, min,   na.rm=TRUE)\r\nmaxSummary  <- sapply(Xymat, max,   na.rm=TRUE)\r\nmedSummary  <- sapply(Xymat, median,na.rm=TRUE)\r\nsummvar <- cbind(meanSummary, medSummary, sdSummary, minSummary, maxSummary)\r\n\r\n#  SUMMARY STATISTICS\r\nprint(\"TABLE 3.1 SUMMARY STATISTICS\")\r\nprint(summvar)\r\n\n<\/script><\/div>\n<p>This feature is great if you are new to <span style=\"font-family: 'American   Typewriter'\">R<\/span>. However, after a while, this approach will become frustrating. You will find that the output is messy. Further, the server will not send back plots and does not have all of the functionality (packages) that you will want. So, after the first few chapters, you will see displays such as:<\/p>\n<h2 style=\"text-align: center;\"><a id=\"displayText6.1d2\" href=\"javascript:togglecode('toggleText6.1d2','displayText6.1d2');\"><i><strong>R Code and Output<\/strong><\/i><\/a> <\/h2>\n<div id=\"toggleText6.1d2\" style=\"display: none\">\n<pre>\r\n<strong>R-Code<\/strong>\r\n#  THIS CODE USES THE DATASET TERMLIFE.CSV\r\nTerm &lt;- read.table(file=\"http:\/\/instruction.bus.wisc.edu\/jfrees\/jfreesbooks\/Regression%20Modeling\/BookWebDec2010\/CSVData\/TermLife.csv\", header=TRUE, sep=\",\")\r\n\r\n#  PICK THE SUBSET OF THE DATA CORRESPONDING TO TERM PURCHASE\r\nTerm2 &lt;- subset(Term, subset=FACE > 0)\r\nTerm2$LNFACE &lt;- with(Term2, log(FACE))\r\nTerm2$LNINCOME &lt;- with (Term2, log(INCOME))\r\n\r\nXymat &lt;- data.frame(Term2$FACE, Term2$INCOME, Term2$EDUCATION, Term2$NUMHH, Term2$LNFACE, Term2$LNINCOME)\r\nmeanSummary &lt;- sapply(Xymat, mean,  na.rm=TRUE)\r\nsdSummary   &lt;- sapply(Xymat, sd,    na.rm=TRUE)\r\nminSummary  &lt;- sapply(Xymat, min,   na.rm=TRUE)\r\nmaxSummary  &lt;- sapply(Xymat, max,   na.rm=TRUE)\r\nmedSummary  &lt;- sapply(Xymat, median,na.rm=TRUE)\r\nsummvar &lt;- cbind(meanSummary, medSummary, sdSummary, minSummary, maxSummary)\r\n\r\n#  SUMMARY STATISTICS\r\nprint(\"TABLE 3.1 SUMMARY STATISTICS\")\r\nprint(summvar)\r\n<\/pre>\n<pre>\r\n<strong>R-Code Output<\/strong>\r\n> print(\"TABLE 3.1 SUMMARY STATISTICS\")\r\n[1] \"TABLE 3.1 SUMMARY STATISTICS\"\r\n> print(summvar)\r\n                 meanSummary   medSummary    sdSummary minSummary   maxSummary\r\nTerm2.FACE      747581.45455 150000.00000 1.674362e+06 800.000000 1.400000e+07\r\nTerm2.INCOME    208974.61818  65000.00000 8.240098e+05 260.000000 1.000000e+07\r\nTerm2.EDUCATION     14.52364     16.00000 2.549221e+00   2.000000 1.700000e+01\r\nTerm2.NUMHH          2.96000      3.00000 1.492756e+00   1.000000 9.000000e+00\r\nTerm2.LNFACE        11.99029     11.91839 1.870728e+00   6.684612 1.645457e+01\r\nTerm2.LNINCOME      11.14910     11.08214 1.295028e+00   5.560682 1.611810e+01\r\n<\/pre>\n<\/div>\n<p>This contains the <span style=\"font-family: 'American   Typewriter'\">R<\/span>-code and the output from it. If you are a passive viewer, this is enough to move you along. Active participants will copy the code into a working session of <span style=\"font-family: 'American   Typewriter'\">R<\/span>, execute it, and analyze it further.<\/p>\n<p><strong>Additonal <span style=\"font-family: 'American   Typewriter'\">R<\/span> Resources<\/strong><br \/>\nI don&#8217;t want this to be an <span style=\"font-family: 'American   Typewriter'\">R<\/span> site in part because I want to focus on actuarial applications of statistical methods but also in part because there are a lot of good resources out there. But here are a few hints that might help you. <\/p>\n<ul>\n<li>For finding commands quickly, I like the <a style=\"font-size: 14px\" href=\"http:\/\/www.statmethods.net\/\" target=\"_blank\" rel=\"noopener\">Quick &#8211; R<\/a> site<\/li>\n<li>I use the  <a style=\"font-size: 14px\" href=\"http:\/\/www.rstudio.com\/\" target=\"_blank\" rel=\"noopener\">R-studio<\/a> platform as a way of organizing my <span style=\"font-family: 'American   Typewriter'\">R<\/span> session.<\/li>\n<li>I often use the <a style=\"font-size: 14px\" href=\"http:\/\/www.rcommander.com\/\" target=\"_blank\" rel=\"noopener\">R-commander<\/a> graphical user interface (GUI) interface when teaching classes to help students get started.<\/li>\n<\/ul>\n<p>So, let&#8217;s get started!<br \/>\n<div class=\"alignleft\"><a href=\"https:\/\/users.ssc.wisc.edu\/~ewfrees\/regression\/\" title=\"Regression Modeling\">&#9668 Previous page<\/a><\/div><div class=\"alignright\"><a href=\"https:\/\/users.ssc.wisc.edu\/~ewfrees\/regression\/book-resources\/\" title=\"Book Resources\">Next page &#9658<\/a><\/div><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I hope that you find this site useful while commuting to work or school or in quiet times while sitting on an easy chair thinking deep thoughts. Personally, I find that these are times when a book (hard-copy or electronic) is more suitable for my learning style. But, to each their own. Active Learning For&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":1713,"menu_order":0,"comment_status":"closed","ping_status":"open","template":"","meta":{"jetpack_post_was_ever_published":false},"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/P8cLPd-MZ","acf":[],"_links":{"self":[{"href":"https:\/\/users.ssc.wisc.edu\/~ewfrees\/wp-json\/wp\/v2\/pages\/3037"}],"collection":[{"href":"https:\/\/users.ssc.wisc.edu\/~ewfrees\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/users.ssc.wisc.edu\/~ewfrees\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/users.ssc.wisc.edu\/~ewfrees\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/users.ssc.wisc.edu\/~ewfrees\/wp-json\/wp\/v2\/comments?post=3037"}],"version-history":[{"count":24,"href":"https:\/\/users.ssc.wisc.edu\/~ewfrees\/wp-json\/wp\/v2\/pages\/3037\/revisions"}],"predecessor-version":[{"id":6504,"href":"https:\/\/users.ssc.wisc.edu\/~ewfrees\/wp-json\/wp\/v2\/pages\/3037\/revisions\/6504"}],"up":[{"embeddable":true,"href":"https:\/\/users.ssc.wisc.edu\/~ewfrees\/wp-json\/wp\/v2\/pages\/1713"}],"wp:attachment":[{"href":"https:\/\/users.ssc.wisc.edu\/~ewfrees\/wp-json\/wp\/v2\/media?parent=3037"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}