Some (very) basic R commands for simple statistics: Difference between revisions

From Brain Mapping Unit
Jump to navigationJump to search
(Created page with "==Statistical Methods== '''(Very) Basic R Commands''' To install packages: ''install.packages("package")'' To run library: "library(package)" '''Useful packages:''' library(...")
 
No edit summary
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
==Statistical Methods==


'''(Very) Basic R Commands'''
To install packages: <code>install.packages("package")</code>


To install packages: ''install.packages("package")''
To run library: <code>library(package)</code>
 
To run library: "library(package)"


'''Useful packages:'''
'''Useful packages:'''


<code>
library(xlsx)
library(xlsx)


Line 26: Line 24:


library(lme4)
library(lme4)
</code>


'''The help function:'''
'''The help function:'''


"?? query"   (I.e. ?? lm)
<code>?? query</code>   (I.e. <code>?? lm</code>)


'''To import data on an excel sheet:'''
'''To import data on an excel sheet:'''


"library(xlsx)"
<code>
 
library(xlsx)
"Data <- read.xlsx("Data.xlsx", sheet no.)"
Data <- read.xlsx("Data.xlsx", sheet no.)
 
attach(Data)
"attach(Data)"
</code>


'''To generate a subset of a dataframe:'''
'''To generate a subset of a dataframe:'''


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


'''Linear Analysis:'''
'''Linear Analysis:'''


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


Line 60: Line 60:


"boxcoxfit(Data$a)"
"boxcoxfit(Data$a)"
</code>


'''Diagnostic tests:'''
'''Diagnostic tests:'''


<code>
"par(mfrow=c(2, 3))"
"par(mfrow=c(2, 3))"


"plot(m, which=1:6)"
"plot(m, which=1:6)"
</code>


'''Plotting:'''
'''Plotting:'''
Line 73: Line 76:
Other basic plotting;  
Other basic plotting;  


<code>
"plot(x, y)"
"plot(x, y)"


Line 78: Line 82:


"abline(m, col="red")"
"abline(m, col="red")"
</code>
===Back To Main Page===
[[Main Page]]

Latest revision as of 19:54, 1 April 2016

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")"

Back To Main Page

Main Page