open source!
# Generate HTML view of script
publish('run_analysis.m');
# View HTML
web('html/run_analysis.html')
http://stanford.edu/class/psych252/tutorials/index.html```{r load_data}
behav_filepath = '~/Dropbox/Code/tutorial/objfam_groupcat_euc.csv'
# Load data
df = read.csv(behav_filepath)
# Examine data structure
summary(df)
str(df)
```
```{r load_data}
behav_filepath = '~/Dropbox/Code/tutorial/objfam_groupcat_euc.csv'
# Load data
df = read.csv(behav_filepath)
# Examine data structure
summary(df)
str(df)
```
Naming chunks helps navigate script
Plot data
----------
- Specify height & width of plot
- Hide code
```{r plot_data, fig.height=3, fig.width=7, echo=FALSE}
boxplot(Response~Morph, data=df)
```
Specify plot dimensions
hide code in knit file
General linear model analysis
----------------------
### Does Euclidean distance vary as a function of morph level?
```{r stats}
rs1 = lm(EuclidDist~scale(Morph, scale=FALSE), data=df)
summary(rs1)
final_model = rs1
sm = summary(final_model)
```
#### Stats Summary:
Euclidean distance significantly varies as a function of morph level,
$R^2$ = `r sm$r.squared`,
*F*(`r sm$fstatistic['numdf']`, `r sm$fstatistic['dendf']`) =
`r sm$fstatistic['value']`,
*t* = `r sm$coefficients[6]`,
*estimate* = `r sm$coefficients[2]`.
LaTeX style text & inline code
```{r, echo = FALSE}
sliderInput("morph", "Morph level:", min = 1, max = 3, value = 2)
renderPlot({
# Subset data
df_subset = df[df$Morph==input$morph,]
# draw the histogram with the specified morph level
with(df_subset, hist(Response,
col = 'darkgray',
border = 'white'))
})
```
input to plot
http://stanford.edu/class/psych252/tutorials/index.html
http://stanford.edu/class/psych252/plots/index.html
Thorough Tutorials:
Quick Resources:
Other:
Install packages via pip
Make sure the environment variable PATH is set to the Anaconda location
export PATH=~/anaconda/bin:$PATHpip install <package-name>ipython notebookpip install rpy2# Load R extension
%load_ext rpy2.ipython
# Import dataframe df to R
%R -i df
# New code block:
%%R
print(str(df))
pip install rpy2
NBViewer: html
Github: .ipynb file