Introduction to R & biostatistics

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/36

encourage image

There's no tags or description

Looks like no tags are added yet.

37 Terms

1
New cards

Run 2+7

2
New cards

Run sqrt(2)

3
New cards

Run a vector for 1-10 and store it in ‘x’ and calculate its mean

4
New cards

Run a matrix with data = 1to10 row = 2 col = 5

5
New cards

Summarise the matrix you made

6
New cards
expression <- matrix(
  c(12, 15, 18,
    20, 17, 22,
    14, 19, 16,
    25, 21, 23),
  nrow = 4,
  ncol = 3,
  byrow = TRUE
)

Display the matrix expression.

Extract the expression level of Gene B in sample 3.

Extract the entire second row.

Extract the entire third column.

Replace the value in row 1, column 1 with 30.

Use dim() to find the dimensions of the matrix.

Use ls() to see which objects you have created.

Use summary() on the matrix.


7
New cards
age <- c(22, 35, 48, 56, 29, 67, 41, 52, 18, 73)

Write R commands to:

  1. Identify patients older than 50.

  2. Identify patients younger than or equal to 40.

  3. Select patients aged between 30 and 60 using &.

  4. Select patients younger than 30 OR older than 65 using |.

  5. Select patients who are NOT older than 50 using !.

  6. Select patients whose ages are either 22, 48 or 73 using %in%.

  7. Count how many patients are older than 50.


8
New cards
patient_id <- c(101, 102, 103, 104, 105, 106)

treatment <- c("Chemo", "Radio", "Chemo", "Radio", "Chemo", "Radio")

age <- c(45, 62, 38, 55, 71, 49)

response <- c(1, 0, 1, 1, 0, 1)
  • Create a data frame called patients containing all four variables.

  • Display the complete data frame.

  • Extract only the age column using $.

  • Extract the treatment and response columns using column indexing.

  • Extract rows 2, 4 and 6, showing only patient_id and age.

  • Find the dimensions of the data frame using dim().

  • Display the first six rows using head().

  • Display the structure of the data frame using str().

  • Generate a statistical summary using summary().

  • Extract all columns except patient_id.


9
New cards

A researcher is analysing an oncology dataset.

  1. Create an object called patient_age containing the values 34, 45, 56, 62 and 71.

  2. Display all objects currently in your workspace.

  3. Save the complete workspace as oncology.RData.

  4. Save only the object patient_age as age_data.RData.

  5. Remove the object patient_age.

  6. Load age_data.RData back into R.

  7. Find your current working directory.

  8. Change your working directory to a folder called Oncology_Project (use a path that exists on your computer).


10
New cards

You have a file called patients.csv containing patient information.

  1. Write an R command to import this CSV file and store it as patients.

  2. Import a tab-delimited file called patients.txt.

  3. Import a general text file using read.table(), specifying that the first row contains column names.


11
New cards
tumour_size <- c(2.1, 3.5, 4.2, 5.1, 6.0)
  • Calculate the mean tumour size.

  • Calculate the logarithm of 100 using base 10.

  • Calculate the square root of the mean tumour size.

  • Store the result of the mean in an object called mean_size.

  • Display the help documentation for mean().


12
New cards
age <- c(34, 45, NA, 62, NA, 71, 56)
  1. Identify which observations are missing.

  2. Count the number of missing and non-missing observations.

  3. Calculate the mean age.

  4. Calculate the mean age after removing missing values.

  5. Calculate the median age after removing missing values.

  6. Create a table that includes missing values.


13
New cards

A clinical researcher records treatment allocation:

treatment <- c(
  "Chemotherapy",
  "Radiotherapy",
  "Chemotherapy",
  "Immunotherapy",
  "Radiotherapy",
  "Immunotherapy"
)
  1. Convert treatment into a factor.

  2. Display its levels.

  3. Display the internal numerical representation of the factor.

  4. Create a factor with the levels ordered as follows:

    • Immunotherapy

    • Chemotherapy

    • Radiotherapy

  5. Change the reference group to Radiotherapy using relevel().

  6. Count the number of patients in each treatment group using table().


14
New cards

A researcher wants to investigate whether age and treatment type are associated with tumour response.

Write the appropriate R formulas for:

  1. Tumour response explained by age.

  2. Tumour response explained by age and treatment.

  3. Tumour response explained by age, treatment and their interaction.

  4. An interaction term between age and treatment only.

  5. Tumour response explained by the logarithm of age.


15
New cards

A researcher fits a linear regression model:

model <- lm(tumour_size ~ age, data = patients)

Write the R command to:

  1. Display a short model output.

  2. Display a detailed model summary.

  3. Extract the regression coefficients.

  4. Extract the residuals.

  5. Obtain the confidence intervals.

  6. Obtain the fitted values.

  7. Predict tumour size for new patients with ages 40 and 60.


16
New cards

The dataset is currently in wide format:

patients <- data.frame(
  patient_id = c(1, 2, 3, 4, 5, 6),
  baseline = c(5.2, 4.8, 6.1, 5.5, 7.0, 4.9),
  month_3 = c(4.8, 4.2, 5.5, 5.0, 6.2, 4.5),
  month_6 = c(4.1, 3.9, 4.8, 4.4, 5.5, 4.0)
)

Tasks:

  1. Load the tidyr package.

  2. Convert the dataset from wide to long format using pivot_longer().


17
New cards

The dataset is currently in long format:

response <- data.frame(
  patient_id = c(1, 1, 1, 2, 2, 2, 3, 3, 3,
                 4, 4, 4, 5, 5, 5),
  time = rep(c("baseline", "month_3", "month_6"), 5),
  response = c(2, 4, 6,
               3, 5, 7,
               1, 3, 5,
               4, 5, 6,
               2, 3, 4)
)

Tasks:

  1. Convert the dataset from long to wide format using pivot_wider().


18
New cards

What is Descriptive statistics 

what do the data look like, and can

they be trusted?

19
New cards

What is Confidence intervals 

how uncertain is my estimate?

20
New cards

What is Diagnostic testing statistics

sensitivity, specificity, and the

number often misunderstood: the predictive value of a positive

test

21
New cards

3 types of data

•Binary data: HPV status (infected/not infected), myocardial- t-test, ANOVA, linear regression

infarction (yes/no), alive

•Continuous data: cholesterol, triglyceride concentration, quality of life- chi2, logistic regression

•Time-to-event data (survival): time to death, time to

recurrence after treatment, time to get employed- Kaplan-Meier, log-rank, Cox

22
New cards

Shapes of distribution

knowt flashcard image
23
New cards

Measures of center

Mean

Median

Mode

24
New cards

If the distribution is right-skewed, then

Median < mean

25
New cards

What are the Measures of spread/dispersion (no need to know the formulas)

•Standard deviation

•Variance

•Range

•Interquartile range

26
New cards

Common practice in medical articles

•For symmetric distributions, report mean and SD

•For skewed distributions, report median and IQR

•For proportions, report n and % (GOOD TO KNOW)

27
New cards

Pearson correlation

r = +1 perfectly positive linear association

r = 0 no linear association

r = -1 perfectly negative linear association


Correlation tells you X and Y move together , but not why

28
New cards

What is the mean FEV1 in a population of children aged 7 – 10

year?

Sample: N = 636 children, mean is 1.59 L, SD = 0.30

The confidence interval is good because the mean falls between it.

<p>The confidence interval is good because the mean falls between it. </p>
29
New cards

Defind Confidence interval for mean

An interval, derived from sample data, that has a specified probability (such as 95%) of containing the true population parameter (here the mean) if the sampling process is repeated indefinitely

30
New cards

What proportion of children in a population of children aged 7 –

10 year have an FEV1 <1.5L?

> mean(fev1 < 1.5)= 0.3726415

knowt flashcard image
31
New cards

Can a Covid-19 test correctly distinguish Covid-19 cases from healthy controls?

Sensitivity and specificity do not directly inform on the

predictive value of a positive or negative tests. So you can perform

Positive predictive value (PPV)

= positive cases / number of positives

Negative predictive value (NPV)

= negative controls / number of negatives

32
New cards

Descriptive statistics

A researcher investigates tumour volumes in 200 patients diagnosed with lymphoma. The following summary statistics are obtained:

Measure

Result

Mean tumour volume

710 ml

Median tumour volume

410 ml

Standard deviation

855 ml

Minimum

50 ml

Maximum

6,050 ml

Interquartile range

760 ml

1. Based on the mean and median, what can you conclude about the shape of the distribution? Explain your answer. (2 points)

2. Which measure of central tendency would you prefer to report: mean or median? Explain why. (2 points)

3. Explain the difference between standard deviation and variance. (2 points)

4. What does the interquartile range tell you about this dataset? (2 points)

5. The researcher creates a boxplot and observes several points above the upper whisker. What do these points represent, and how are potential outliers defined using the IQR? (3 points)


33
New cards

Confidence intervals

A clinical researcher investigates the mean reduction in tumour volume after six months of chemotherapy.

The study includes 100 patients.

The results are:

  • Mean reduction: 12 mm

  • Standard deviation: 8 mm

  • Sample size: 100

1. Calculate the standard error of the mean. (2 points)

2. Calculate the 95% confidence interval for the population mean reduction using:

\[ 95\%\,CI=\bar{x}\pm1.96\times SE \]

(3 points)

3. Interpret the confidence interval in the context of this study. (2 points)

4. Suppose another study uses a sample of 400 patients, with the same standard deviation and mean. Would its confidence interval be wider or narrower? Explain why. (2 points)

5. Explain why a 95% confidence interval does not mean that there is a 95% probability that the true population mean lies within this particular calculated interval. (2 points)

34
New cards

Diagnostic testing

Researchers develop a new blood test to detect an early-stage cancer. Histopathological examination is used as the gold standard.

The test is evaluated in 1,000 individuals.

The results are:

Blood test

Cancer present

Cancer absent

Total

Positive

45

95

140

Negative

5

855

860

Total

50

950

1,000

1. Calculate the sensitivity of the blood test. (2 points)

2. Calculate the specificity of the blood test. (2 points)

3. Calculate the positive predictive value (PPV). (2 points)

4. Calculate the negative predictive value (NPV). (2 points)

5. A patient receives a positive test result. What is the probability that this patient actually has cancer, based on this study? Which diagnostic measure answers this question? (2 points)

6. Explain why a test can have high sensitivity and specificity but a relatively low PPV. (3 points)

35
New cards

Prevalence and predictive values

A screening test for a rare cancer has:

  • Sensitivity = 90%

  • Specificity = 95%

The test is used in two populations, each containing 1,000 individuals.

Population A: Cancer prevalence = 1%.

Population B: Cancer prevalence = 30%.

1. Calculate the number of individuals with cancer and without cancer in each population. (2 points)

2. For Population A, calculate:

  • True positives.

  • False positives.

  • PPV.

(3 points)

3. For Population B, calculate the same three values. (3 points)

4. Compare the PPV between the two populations. Why does it differ even though sensitivity and specificity remain unchanged? (3 points)

5. What happens to NPV when disease prevalence increases? Explain using these two populations. (2 points)

36
New cards

Confidence interval for a proportion

A study investigates the proportion of patients who respond to a new immunotherapy.

Out of 200 patients, 120 show a clinical response.

1. Calculate the observed response proportion. (1 point)

2. Calculate the standard error of the proportion using:

\[ SE_p=\sqrt{\frac{p(1-p)}{n}} \]

(2 points)

3. Calculate the 95% confidence interval for the response proportion. (2 points)

4. State the assumption underlying the confidence interval formula presented in the lecture. (2 points)

37
New cards

R questions

A researcher collects tumour volume measurements (ml) and patient ages (years) from 10 oncology patients.

volume <- c(120, 150, 180, 200, 250,
            300, 350, 420, 600, 1500)

age <- c(35, 42, 50, 55, 61,
         48, 67, 72, 58, 75)

1. R-question. Calculate the mean, median and standard deviation of tumour volume. Show your code. (3 points)

2. R-question. Calculate the 25th and 75th percentiles of tumour volume. (2 points)

3. R-question. Create a histogram of tumour volume. (1 point)

4. Based on the histogram and summary statistics, would you describe the distribution as symmetric or skewed? Which measure of central tendency would you report? Explain. (2 points)

5. R-question. Create a boxplot of tumour volume and add horizontal lines indicating the first quartile, median and third quartile. (3 points)

6. R-question. Create a scatterplot showing the relationship between age and tumour volume. (2 points)

7. R-question. Calculate the Pearson correlation coefficient between age and tumour volume. (1 point)

8. Interpret the correlation coefficient. Does it establish that increasing age causes tumour volume to increase? Explain. (2 points)