• Wrong document? Swap it for free
  • Written by students who passed
  • Immediately available after payment
  • Read online or as PDF
Sell
Where do you study
Your language
Document preview thumbnail
Preview 4 out of 50 pages
Summary

Summary R Programming | Data Science & Biostatistics | VU Amsterdam

Document preview thumbnail
Preview 4 out of 50 pages

Summary for the R Programming course in Data Science & Biostatistics at VU Amsterdam. Topics include R syntax and data structures (vectors, matrices, data frames), the five stages of statistical analysis (data import, inspection, analysis, validation, reporting), and practical statistical methods including ANOVA, multiple comparisons, and p-value corrections (Bonferroni, Benjamini-Hochberg). Essential reference for mastering R programming techniques and statistical analysis workflows required in the Personalized Medicine course. I achieved a 10/10 in the exam (by using the practical guide I added at the end of the summary)!

Content preview

Con ten ts
01 Introduction to programming in R

02 Lecture (not in summary):

03 Hypothesis testing

04 Biostatistics – continuous outcomes

05 Binary outcomes

06 Survival analysis

07 Confounding and modifying

08 Prediction models

09 Repeated measures

10 Multiple testing

11 Overall summary: tests

12 Practical guide; How to perform tests in R




Data science · study summary

, lecture 01

Intr oduction to pr ogr am m ing in R
Data Science & Bioinformatics




Overview of R
Definition: R is described as a language and environment for statistical computing and graphics, available as a
free, open-source package compatible with all major operating systems.
Capabilities: It includes basic statistical procedures and allows for extensions through additional packages.



Statistical Analysis Stages
The presentation outlines five stages in statistical analysis:
Importing Data: Bringing data into R for analysis.
Data Inspection: Identifying errors and cleaning data, including recoding and summarizing.
Analysis: Estimating parameters, assessing uncertainty (confidence intervals, p-values), and determining
predictive values.
Model Validation: Checking assumptions of the model used.
Reporting Results: Summarizing findings through tables and graphics.



Basic Syntax and Data Structures
Data Structures: Key structures include vectors, matrices, modes, and data frames.
Vectors: Defined using c(), allowing for indexing and operations on elements.
Matrices: Two-dimensional structures that can be indexed similarly to vectors.
Data Frames: Tables that allow mixed data types, where each column can represent different modes.

Help pages always have the same lay-out:
Description -> usage -> arguments -> value -> details -> example.

Columns run vertically, rows run horizontally. In R, you specify [row,column] (row before column).




Giving names to variables
Be aware when giving variables names, no space or special characters! Also, numbers are not allowed as the first
characters. _ and . can be used to separate names. Names are case sensitive.

R has several modes:
Numeric -> 1,2,3,4, etc
Logical -> Boolean values (TRUE, FALSE)
== : test for equality and != : test for inequality.
Booleans are converted to numeric values. TRUE equals 1, FALSE equals 0. By applying sum, you can count
the numbers 1, which is the same as counting all the TRUEs.
Character -> between “.




Data science · study summary

, lecture 02

Lectur e (not in sum m ar y):
Data Science & Bioinformatics



Ctrl L = clear console.
Ctrl R = run script.

Would like to store your value in a certain variable, so you can use it e.g. as the argument of a function. In R, do
this with <-.
Functions are really important. The inputs are specified via arguments of the function between ():
Name_of_function(argument_1, argument_2).
Functions are in a general part of a package. Library() shows the packages installed on your computer.

Help-packages:
library(foreign) to make the package visible for your laptop. Read.dta was already installed, but r couldn’t see it.
Now, it can.

Trimmed mean
If e.g. trim=0.2, the 20% lowest and 20% highest values are left out and then the mean is calculated. Can leave
out the extreme values at the low and high end.

Help page:
Always same lay-out. Description usage arguments value details example.

Often you work with a series of numbers. How to make a single “factor” (e.g. patient name, patient number, drug,
etc). use the function c to make a vector:
> x <- c(10, 9, 8, 7, 6, 5, 4, 3, 2, 1)
Always different ways to do it:
x <- seq(from = 10, to = 1, by = -1) OR
x <- seq(10, 1) OR
x <- 10:1

if you don’t know the function very well, including the names in the function (like the first different way) can
already help you to understand. Only if you really understand it, start leaving more out like x <- 10:1.

# allows you to make comments in your script that wont be run.

Quite often you need to make a selection from a certain variable. E.g. separate analysis on patients over and
under 18. To extract an element from the data, you use []. First indicate the vector, and then the element you
want to extract. E.g. x[10]. To extract multiple elements, you first need to make a vector of the elements you want
to extract. indx <- c(5,10). Then do x[indx] to extract the elements 5 and 10 from the vector x. can also
do it like this:
c(-5, -10)
x[c(-5, -10)]

A matrix has 2 dimensions (rows and columns). Usage:
matrix(data = NA, nrow = 1, ncol = 1, byrow = FALSE, dimnames = NULL)

can either put the numbers in it by column or by row. By column means we start in the left upper corner and then
go down. In the example in the code this is the case. If byrow= FALSE, the numbers are put in the matrix by
column (default). If byrow = TRUE, the numbers are put in the matrix by row (left to right, then down).
[row,column]

Giving names to variables

Data science · study summary

, Often better for your code to use names that actually mean something. Be aware, no space or special characters!
Also, numbers are not allowed as the first characters. _ and . can be used to separate names. Names are case
sensitive. A and a are different variables. Also goes for Data and data.

Summary
Will give you a short summary of the variable. Useful to get a feel of the data you are working with, especially if
you import data from somewhere else.

R has several modes:
Numeric -> 1,2,3,4, etc
Logical -> Boolean values (TRUE, FALSE)
Very important. Can use TRUE/FALSE to select data. Can make a vector from e.g. numbers between 0 to 10
randomly. Then select all the ones greater than 5. Will get a list with true or false. Then, can select on the
trues to get all the values above 5.
== : test for equality and != : test for inequality. %in% c(3,8) to make a list of trues and falses in the
vector to see which ones are equal to 3 and 8.
Booleans are converted to numeric values. TRUE equals 1, FALSE equals 0. By applying sum, you can count
the numbers 1, which is the same as counting all the TRUEs.
Can also select on 2 (or more) valuables instead of just 1 (e.g. age and gender).
&: AND - all must be true
|: OR - at least one must be true
!: NOT - negation
Character between “.

Data frames
Columns and rows. Columns now have names. Better to use this in the code to make it more clear. Use names
between “ instead of numbers.
titanic[c(2,3),] # Or by name
titanic[,c("name","age")]
can also extract data for e.g. the variable age by using $:
titanic$age

dim(titanic) will give you the dimensions (number of rows and columns) of the data frame.
head(titanic) will give you the first few rows of the data frame.
tail(titanic) will give you the last few rows of the data frame.


To install a package that you don’t have yet, use the function install.packages("package")

install.packages("dplyr") and arrange function can arrange data.
E.g. titanic.SortedAge <- arrange(titanic3, age) that will sort on age from high to low.

To save a variable/data set, do this:
save(name dataset, file=”name.RData”)
E.g. save(titatnic3, file=”Titanic.RData’)

getwd() to get the working directory (where R is looking for/storing the data.
rm(name variable) to get rid of 1 of the variables in your working space.
Can use setwd() to set the working directory right, go to session in the menu and set working directory, or replace
the file to the working directory you’re in.

is.na(name) to see where the missing values are.
mean(name, na.rm = TRUE) to exclude the missing values in the table from the calculations.


Subset makes the selection a lot shorter.


Data science · study summary

Document information

Study
Uploaded on
September 1, 2026
Number of pages
50
Written in
2024/2025
Type
Summary
$9.84

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Sold
1
Followers
0
Items
14
Last sold
3 weeks ago



Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions