Some (very) basic R commands for simple statistics

From Brain Mapping Unit
Revision as of 23:44, 10 April 2012 by pv226 (talk | contribs) (Created page with "==Statistical Methods== '''(Very) Basic R Commands''' To install packages: ''install.packages("package")'' To run library: "library(package)" '''Useful packages:''' library(...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Statistical Methods

(Very) Basic R Commands

To install packages: install.packages("package")

To run library: "library(package)"

Useful packages:

library(xlsx)

library(geoR)

library(ggplot2)

library(HH)

library(nortest)

library(tseries)

library(fUtilities)

library(nlme)

library(lme4)

The help function:

"?? query" (I.e. ?? lm)

To import data on an excel sheet:

"library(xlsx)"

"Data <- read.xlsx("Data.xlsx", sheet no.)"

"attach(Data)"

To generate a subset of a dataframe:

"subset.data <- subset(Data, factor=="group1")"

Linear Analysis:

"m <- lm(a ~ b, data=Data)"

"summary(m)"

"drop1(m, test="F")"

"ancova(a ~ b*factor, data=Data)"

"t.test(Data$a, Data$b)"

"cor.test(Data$a, Data$b, method="spearman")"

"ad.test(Data$a)"

"boxcoxfit(Data$a)"

Diagnostic tests:

"par(mfrow=c(2, 3))"

"plot(m, which=1:6)"

Plotting:

The package "ggplot2" makes lovely figures and there are many guides for how to use it on the web.

Other basic plotting;

"plot(x, y)"

"m <- lm(y ~ x)"

"abline(m, col="red")"