1 + 1[1] 2
I have left some instructions from R Studio in place. You will get similar instructions anytime you use the File menu to create a new Quarto Document, Quarto Presentation, R Markdown, or R Notebook. You will not get anything but a blank document if you create an R Script.
If I fail to remove any references to Blackboard, please read them as “Canvas.”
Quarto enables you to weave together content and executable code into a finished document. To learn more about Quarto see https://quarto.org.
When you click the Render button a document will be generated that includes both content and the output of embedded code. You can embed code like this:
1 + 1[1] 2
You can add options to executable code like this
[1] 4
The echo: false option disables the printing of code (only output is displayed).
Run code in R Studio or R Studio Cloud. Download the finished HTML or PDF file and upload to Canvas by the September 20 for full credit
The areas with ``` followed by {r} and ending with ``` are code chunks. The Run dropdown arrow in the upper right of this box give you options for running the code. Run Current Chunk runs just the piece you are working on. After you have finished, you can Run all then save the result. Where you see Preview (above just left of center) there is a dropdown arrow. If you select “Render”, including “Render to HTML” or “Render to PDF”, you can produce a copy that can be downloaded and submitted in Canvas.
IF all else fails, screenshot your work, make a note of anything you did to resolve any errors, and submit that in Canvas.
You do not need to do anything fancy, but For more help with RMarkdown and Quarto here are some resources:
R Markdown is a language based on R and a general language called Markdown. Quarto is a system for publishing documents and presentations written using R Markdown. Both are included in R Studio/Posit
Cheatsheet - https://rmarkdown.rstudio.com/lesson-15.HTML
Code Chunks - https://rmarkdown.rstudio.com/lesson-3.html
R Markdown Cookbook - https://bookdown.org/yihui/rmarkdown-cookbook/
Quarto - https://quarto.org/
#Hint: use the assignment operator <- to assign the value
#use the c function - c() - to create the sequence
my_vector <- c(1,2,3,4,5)object_sum <- sum(my_vector)
object_sum[1] 15
Answer: 15
n <- as.numeric(length(my_vector))
n[1] 5
object_mean <- object_sum / n
object_mean[1] 3
#To get help with a function, you can use ?
#For some non-base functions, you may need to use ??
?meanstarting httpd help server ... done
mean_check <- mean(my_vector)
mean_check[1] 3
my_pop_variance <- sum((my_vector - object_mean)^2)/n
cat('population variance')population variance
my_pop_variance[1] 2
my_sample_variance <- sum((my_vector - object_mean)^2)/(n-1)
cat('sample variance')sample variance
my_sample_variance[1] 2.5
There are two simple ways to do this:
my_population_sd <- sqrt(my_pop_variance)
cat('population standard deviation')population standard deviation
my_population_sd[1] 1.414214
my_sample_sd <- sqrt(my_sample_variance)
cat('sample standard deviation')sample standard deviation
my_sample_sd[1] 1.581139
with 5 numbers, just counting to the middle number is easy and you can do that to check. It’s also an acceptable answer. Here is the R code:
my_median <- median(my_vector)
cat('median')median
my_median[1] 3
Answer: 2
What is your favorite food? Pizza. While this is the only rational, correct answer except maybe tacos, you get full points for answering with your own irrational cravings.
What is your Github username? tomhanna-uh [Note: This is public so there is no concern with revealing it.]
What is the name of your project data set? demonstration_data.csv
What is the source of your project data set? The Varieties of Democracy [VDem] Project version 13.
What would you like to learn from the data set in one or two sentences? (How to use data/R studio/statistics is an acceptable answer.)
Answer: I am interested in exploring this particular bit of data just to see what correlation is there. This is purely exploratory. I am mostly using this as a demonstration for all of you to follow along.
(optional) How many variables does your data have that you will use? How many observations does your data have? There are 12 in the data set I created. I have not decided which ones I will use.
(Optional) Does your data have observations across multiple time periods with separate observations for each time period? No. I subsetted the data for a single year. This is the same procedure and source as the Mini Datasets I uploaded to Canvas and which any of you may use.
For the remaining problems, you can use math operations or R functions. You can use the methods above (creating objects, etc.) or you can just run the functions on the raw numbers. You may also work out the problems by hand, showing your work
second_vector <- c(5,10,15,20,25,30,35,40)
sum_second_vector <- sum(c(second_vector))
sum_second_vector[1] 180
n_2 <- as.numeric(length(second_vector))
n_2[1] 8
Answer:
mean_second_vector <- mean(second_vector)
mean_second_vector[1] 22.5
sample_variance_second_vector <- var(second_vector)
sample_variance_second_vector[1] 150
sample_standard_deviation_second_vector <- sd(second_vector)
sample_standard_deviation_second_vector[1] 12.24745
median_second_vector <- median(second_vector)
median_second_vector[1] 22.5
third_vector <- c(3,7,5,5,6,7,7,9)
sum_third_vector <- sum(third_vector)
sum_third_vector[1] 49
Answer: 5
third_n <- as.numeric(length(third_vector))
third_n[1] 8
mean_third_vector <- mean(third_vector)
mean_third_vector[1] 6.125