Unformatted text preview:

Common STAT 101 Commands for RStudio Professor Kari Lock Morgan For bootstrapping and randomization load resample and reallocate source shared kari lock morgan gmail com simulation R 1 One Categorical Variable table x barplot table x resample x gives a bootstrap distribution and CI for proportion level confidence level default 95 pnorm z qnorm 0 975 gives probability in tail of N 0 1 below z lower tail FALSE for upper tail above z replace 0 975 with desired percentile of N 0 1 prop test count n p null value normal based inference for a single proportion conf level confidence level default 95 alternative two sided less or greater default two sided chisq test table x goodness of fit test p c p1 p2 null values default null all equal simulate p value TRUE calculates p value by simulation B 10000 number of simulations used default 2000 chisq test c count1 count2 count3 if entering counts from table 2 One Quantitative Variable xlab label for x axis main title of plot na rm TRUE to get rid of NA values hist y mean y median y sd y summary y resample y pt t df gives a bootstrap distribution and CI for mean level confidence level default 95 gives probability in tail of a t distribution below t lower tail FALSE for upper tail above t 1 qt 0 975 df t test y mu null value replace 0 975 with desired percentile of t distribution t based inference for a single mean conf level confidence level default 95 alternative two sided less or greater default two sided 3 Two Categorical Variables table x y barplot table x y beside TRUE for side by side barplot legend TRUE to include a color legend mosaicplot table x y resample x y gives a bootstrap distribution and CI for difference in proportions level confidence level default 95 reallocate x y pnorm z qnorm 0 975 randomization test for difference in proportions gives probability in tail of N 0 1 below z lower tail FALSE for upper tail above z replace 0 975 with desired percentile of N 0 1 prop test c count1 count2 c n1 n2 normal based inference for a difference in proportions conf level confidence level default 95 alternative two sided less or greater default two sided chisq test table x y chi squared test for an association between x and y simulate p value TRUE calculates p value by simulation B 10000 number of simulations used default 2000 4 One Categorical and One Quantitative Variable y quantitative x categorical by y x mean by y x sd boxplot y x resample y x na rm TRUE to get rid of NA values gives a bootstrap distribution and CI for difference in means level confidence level default 95 reallocate x y pt t df randomization test for difference in means gives probability in tail of a t distribution below t 2 qt 0 975 df t test y x t test y1 y2 lower tail FALSE for upper tail above t replace 0 975 with desired percentile of t distribution t based inference for a difference in means conf level confidence level default 95 alternative two sided less or greater default two sided if the two categories are given as different vectors of quantitative variables summary aov y x ANOVA for difference in means 5 Two Quantitative Variables plot x y cor x y resample x y xlab label for x axis ylab label for y axis main title for plot use complete obs to get rid of NA values gives a bootstrap distribution and CI for correlation level confidence level default 95 reallocate x y pt t df randomization test for correlation gives probability in tail of a t distribution below t lower tail FALSE for upper tail above t qt 0 975 df cor test x y replace 0 975 with desired percentile of t distribution t based inference for a correlation conf level confidence level default 95 alternative two sided less or greater default two sided 6 Regression model lm y x1 x2 data dataname y response variable x1 x2 any number of explanatory variables summary model plot model gives output for the model produces multiple plots including a residual plot of residuals versus predicted values and a normal q q plot of the residuals predict model gives predicted values for each case interval confidence gives confidence intervals for each case interval prediction gives prediction intervals for each case 3 newdata as data frame cbind x1 x1value x2 x2value only enter numeric variables this way for categorical variables add the values to newdata with newdata x3 yes for each categorical variable predict model newdata gives prediction for a new data point step model performs stepwise regression model glm y x1 x2 data dataname family binomial logistic regression 7 Subsetting subset dataname is na x subset dataname x levelA the data set data but only cases for which x is not NA data dataname but only cases for which x is equal to levelA the variable x but only cases for which x is not NA the variable y but only cases for which x is not NA the variable x but only cases for which x is less than 30 x is na x y is na x x x 30 x x levelA droplevels x the variable x but only cases for which x does not equal levelA drops empty levels if you have removed all the cases from one level 4


View Full Document

UCLA STATS 13 - Common STAT 101 Commands for RStudio

Documents in this Course
lab8

lab8

3 pages

lecture2

lecture2

78 pages

Lecture 3

Lecture 3

117 pages

lecture14

lecture14

113 pages

Lab 3

Lab 3

3 pages

Boost

Boost

101 pages

Noise

Noise

97 pages

lecture10

lecture10

10 pages

teach

teach

100 pages

ch11

ch11

8 pages

ch07

ch07

12 pages

ch04

ch04

10 pages

ch07

ch07

12 pages

ch03

ch03

5 pages

ch01

ch01

7 pages

ch10

ch10

7 pages

Lecture

Lecture

2 pages

ch06

ch06

11 pages

ch08

ch08

5 pages

ch11

ch11

9 pages

lecture16

lecture16

101 pages

lab4

lab4

4 pages

ch01

ch01

7 pages

ch08

ch08

5 pages

lecture05

lecture05

13 pages

Load more
Download Common STAT 101 Commands for RStudio
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Common STAT 101 Commands for RStudio and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Common STAT 101 Commands for RStudio 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?