Example: stock market

Cheat Sheet for R and RStudio - Open Computing Facility

Cheat Sheet for R and RStudioL. Jason AnastasopoulosApril 29, 20131 Downloading and Installation First download R for your OS: R Next download RStudio for your OS: RStudio2 Uploading Data into R-StudioR-Studio Makes uploading CSV files into R extremely simple. Just follow these instructionsand you ll be using R in no Download to a folder that you can easily Open In the interpreter (lower left-hand box of RStudio ), typelibrary(foreign)and hitEnter. This will install the package that reads In the box on the upper-right hand corner of RStudio , click on the tab that says Workspace .5. Then click on Import Dataset>From Text . Find and In the interpreter (lower left-hand box), type inattach(name-of-dataset)and hit En-ter.

Cheat Sheet for R and RStudio L. Jason Anastasopoulos April 29, 2013 1 Downloading and Installation FirstdownloadRforyourOS:R NextdownloadRStudioforyourOS:RStudio ... 3.1 Summary Statistics summary(X) - Summary statistics such as mean,median,mode and quartiles for a variable. > summary(X) Min. 1st Qu. Median Mean 3rd Qu. Max.

Tags:

  Sheet, Statistics, Teach, Cheat sheet

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Transcription of Cheat Sheet for R and RStudio - Open Computing Facility

1 Cheat Sheet for R and RStudioL. Jason AnastasopoulosApril 29, 20131 Downloading and Installation First download R for your OS: R Next download RStudio for your OS: RStudio2 Uploading Data into R-StudioR-Studio Makes uploading CSV files into R extremely simple. Just follow these instructionsand you ll be using R in no Download to a folder that you can easily Open In the interpreter (lower left-hand box of RStudio ), typelibrary(foreign)and hitEnter. This will install the package that reads In the box on the upper-right hand corner of RStudio , click on the tab that says Workspace .5. Then click on Import Dataset>From Text . Find and In the interpreter (lower left-hand box), type inattach(name-of-dataset)and hit En-ter.

2 You can find the name of the dataset listed under the Workspace tab in theupper right-hand corner of To find the variable names in your dataset typenames(name-of-dataset)and Doing statistics in RStudioAfter you have opened your data, doing statistics is really easy. Below is a list of commandsthat you will need to do any kind of statistics in Summary statistics summary(X)- Summary statistics such as mean,median,mode and quartiles for avariable.> summary(X)Min. 1st Qu. Median Mean 3rd Qu. mean(X, )- Produces the mean of the variable. Removes missingobservations.> mean(X, )[1] sd(X, )- Produces the standard deviation of the variable.

3 Removesmissing observations.> sd(X, )[1] Regression lm(Y X)- Runs a regression ofYonXwhereYis yourdependentvariable andXis yourindependentvariable. You need to save your model in R s memory first andcan get the regression coefficients and other info you need by using thesummary()command. For example, for simple regression:> model1 = lm(Y~X)> summary(model1)Call:lm(formula = Y ~ X)Residuals:Min 1Q Median 3Q :Estimate Std. Error t value Pr(>|t|)(Intercept) standard error: on 98 degrees of freedomMultiple R-squared: ,Adjusted R-squared: : on 1 and 98 DF, p-value: multiple > = lm(Y~X + Z)> summary( )Call:lm(formula = Y ~ X + Z)Residuals:Min 1Q Median 3Q :Estimate Std.

4 Error t value Pr(>|t|)(Intercept) .X codes: 0 ** ** * . 1 Residual standard error: on 97 degrees of freedomMultiple R-squared: ,Adjusted R-squared: : on 2 and 97 DF, p-value: plot(X,Y)- Will produce a scatterplot of the variablesXandYwithXon thex-axis andYon the y-axis. abline(regression model)- Will draw a regression line of the regression model thatyou saved through a scatterplot. For example:3> model2 = lm(Y~X)> plot(X,Y)> abline(model2) Hypothesis Testing (X,Y)- Performs a t-test of means between two variablesXandYfor thehypothesisH0: X= Y. Gives t-statistic, p-value and 95% confidence :> (X,Y)Welch Two Sample t-testdata: X and Yt = , df = , p-value = hypothesis: true difference in means is not equal to 095 percent confidence estimates:mean of x mean of Graphics and Plots hist(X)- Will produce a histogram of the variableX.

5 > hist(X) plot(X,Y)- Will produce a scatterplot of the variablesXandYwithXon thex-axis andYon the y-axis.> plot(X,Y)56


Related search queries