Docsity

STATISTICS:R R Programming and Statistical Analysis, Exams of Advanced Education

Toggle sidebar
bg1
S
T
A
T
I
S
T
I
C
S
:
R
R
Programming and Statistical
Analysis
1. What is R?
Correct Answer: R is a free and open-source programming language for statistical
computing and graphics.
Rationale: R is specifically designed for statistical analysis, data manipulation, visualization,
and computational work. Because it is free, open-source, and supported by a large
community, it provides extensive packages and tools for analyzing and presenting data.
2. Why learn R?
Correct Answer: R is built to handle and analyze data.
Rationale: R provides specialized functions and packages for importing, cleaning, analyzing,
visualizing, and modeling data. It is widely used in statistics, research, business analytics, and
data science.
3. What are the two types of data?
Correct Answer: Qualitative (Categorical) and Quantitative (Numeric).
Rationale: Qualitative data describe categories or characteristics, while quantitative data
represent numerical measurements or counts. Correctly identifying the data type helps
determine which statistical methods and visualizations are appropriate.
4. What is a numerical summary?
Correct Answer: A numerical summary provides an overview of data using measures of
center and spread.
Rationale: Numerical summaries condense a dataset into meaningful statistics. Measures of
center, such as the mean and median, describe the typical value, while measures of spread,
such as the range, variance, and standard deviation, describe variability.
5. What is the mean?
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32

Partial preview of the text

Download STATISTICS:R R Programming and Statistical Analysis and more Exams Advanced Education in PDF only on Docsity!

STATISTICS: R R

Programming and Statistical

Analysis

  1. What is R? Correct Answer: R is a free and open-source programming language for statistical computing and graphics. Rationale: R is specifically designed for statistical analysis, data manipulation, visualization, and computational work. Because it is free, open-source, and supported by a large community, it provides extensive packages and tools for analyzing and presenting data.
  2. Why learn R? Correct Answer: R is built to handle and analyze data. Rationale: R provides specialized functions and packages for importing, cleaning, analyzing, visualizing, and modeling data. It is widely used in statistics, research, business analytics, and data science.
  3. What are the two types of data? Correct Answer: Qualitative (Categorical) and Quantitative (Numeric). Rationale: Qualitative data describe categories or characteristics, while quantitative data represent numerical measurements or counts. Correctly identifying the data type helps determine which statistical methods and visualizations are appropriate.
  4. What is a numerical summary? Correct Answer: A numerical summary provides an overview of data using measures of center and spread. Rationale: Numerical summaries condense a dataset into meaningful statistics. Measures of center, such as the mean and median, describe the typical value, while measures of spread, such as the range, variance, and standard deviation, describe variability.
  5. What is the mean?

Correct Answer: The average of data values (sum of values divided by count). Rationale: The mean is calculated by adding all observations and dividing the total by the number of observations. It is commonly used as a measure of central tendency but can be strongly influenced by extreme values.

  1. What is the median? Correct Answer: The value at which half of the data lies above and half lies below it. Rationale: The median is the middle observation after the data have been arranged in order. It is less affected by extreme values than the mean and is therefore useful for skewed distributions.
  2. How do you calculate the median for an odd number of observations? Correct Answer: The median is the kth value where k = (n + 1)/2. Rationale: When there is an odd number of ordered observations, exactly one observation occupies the middle position. The formula identifies that central position.
  3. How do you calculate the median for an even number of observations? Correct Answer: The median is the mean of the kth and (k+1) terms, where k = n/2. Rationale: With an even number of observations, there are two middle values. The median is the average of those two values.
  4. What is an example calculation for mean and median? Correct Answer: Given data: y = 1, 3, 3, 7, 9. Mean = 4.6, Median = 3. Rationale: The mean is calculated as (1 + 3 + 3 + 7 + 9) ÷ 5 = 4.6. Because the ordered dataset contains five observations, the third observation is the median, which is 3.
  5. What functions can be used in R to calculate mean and median? Correct Answer: mean() and median() functions. Rationale: R provides built-in mean() and median() functions that calculate these measures directly from numeric data.
  1. What is a boxplot? Correct Answer: A graphical representation of the distribution of a dataset based on quartiles. Rationale: A boxplot summarizes the distribution using the minimum, Q1, median, Q3, and maximum, while also identifying potential outliers.
  2. What is a histogram? Correct Answer: A graphical representation of the distribution of a dataset using bars. Rationale: A histogram groups quantitative observations into intervals called bins and displays their frequencies. It is useful for examining the shape, center, spread, and possible skewness of a distribution.
  3. What is a scatter plot? Correct Answer: A graphical representation of the relationship between two variables. Rationale: A scatterplot places paired observations on an x-y coordinate system. It is commonly used to examine relationships, trends, clusters, and possible outliers between quantitative variables.
  4. What is variance? Correct Answer: Sum of squares of data points' distance from mean. Rationale: Variance quantifies variability by considering squared deviations from the mean. In formal calculations, the sum of squared deviations is divided by the appropriate denominator depending on whether population or sample variance is being calculated.
  5. What is standard deviation? Correct Answer: Square root of variance. Rationale: Taking the square root of variance returns the measure of spread to the original units of the dataset, making standard deviation easier to interpret.
  6. What is the range? Correct Answer: Maximum value minus minimum value.

Rationale: The range provides the total distance between the smallest and largest observations in a dataset.

  1. What is an example calculation for variance/standard deviation? Correct Answer: Calculation using given data. Rationale: Variance is calculated from deviations of observations from the mean, while standard deviation is the square root of the resulting variance. The exact numerical result depends on the supplied dataset.
  2. What is a quantile? Correct Answer: The point where at least q% of the data values are at or below the value. Rationale: Quantiles divide ordered data according to cumulative proportions. They provide information about the relative position of observations within a distribution.
  3. What are quartiles? Correct Answer: Special quantiles that divide the data into quarters. Rationale: Quartiles divide ordered data into four portions. Q1, Q2, and Q3 correspond approximately to the 25th, 50th, and 75th percentiles.
  4. What is Q1? Correct Answer: The first quartile, also known as the 0.25 quantile. Rationale: Q1 identifies the point below which approximately 25% of the observations fall and marks the lower boundary of the middle 50% of the data.
  5. What is Q2? Correct Answer: The second quartile, also known as the median or the 0.5 quantile. Rationale: Q2 corresponds to the 50th percentile and represents the median of the dataset.
  6. What is Q3? Correct Answer: The third quartile, also known as the 0.75 quantile.

Correct Answer: The smallest value in the dataset. Rationale: The minimum identifies the lowest observed value and represents one endpoint of the dataset's range.

  1. What is Q1 in a five-number summary? Correct Answer: The first quartile. Rationale: Q1 represents the lower quartile and identifies the point associated with approximately the 25th percentile.
  2. What is the median in a five-number summary? Correct Answer: The second quartile. Rationale: The median is Q2, the middle value of the ordered dataset and the 50th percentile.
  3. What is Q3 in a five-number summary? Correct Answer: The third quartile. Rationale: Q3 is the upper quartile and corresponds to approximately the 75th percentile.
  4. What is the maximum in a five-number summary? Correct Answer: The largest value in the dataset. Rationale: The maximum is the highest observed value and represents the upper endpoint of the dataset's range.
  5. What is RStudio? Correct Answer: An integrated development environment (IDE) for R. Rationale: RStudio provides an organized interface for writing and executing R code, viewing variables, managing files, creating plots, and accessing documentation.
  6. What should be installed before RStudio? Correct Answer: R.

Rationale: R is the underlying programming language and computational engine. RStudio provides the development environment through which users interact with R.

  1. Where can RStudio be downloaded from? Correct Answer: https://www.rstudio.com/products/rstudio/download/ Rationale: The supplied address directs users to the RStudio download page. RStudio can then be installed as the development environment for working with R.
  2. Where can R be downloaded from? Correct Answer: https://cran.rstudio.com/ Rationale: CRAN, the Comprehensive R Archive Network, provides R software and a large collection of R packages.
  3. RStudio Environment: What is the purpose of the Script Window? Correct Answer: To draft and save code. Rationale: The Script Window allows users to write, edit, organize, and save R commands before executing them. Saving scripts also makes analysis reproducible.
  4. RStudio Environment: How can you run a script in the console? Correct Answer: Press CTRL+R or CTRL+Enter, or click Run. Rationale: These commands execute selected or current code from the script within the R environment, allowing the results to appear in the Console.
  5. RStudio Environment: What does the Console window display? Correct Answer: Input (blue), output (black), errors or warnings (red). Rationale: The Console provides direct interaction with R by displaying commands, generated results, and diagnostic messages such as errors and warnings.
  6. RStudio Environment: What does the Environment display? Correct Answer: Saved variables and datasets.

Rationale: The print() function displays the specified object or text in the R Console.

  1. R: Hello World!: How can you print multiple items in R? Correct Answer: print(paste('Hello', 'World')) Rationale: The paste() function combines character strings, and print() displays the resulting text.
  2. Try it: R Printing: Question 1: Write an R program that prints 'I am awesome!' Correct Answer: print('I am awesome!') Rationale: The print() function outputs the specified character string to the R Console.
  3. Try it: R Printing: Question 2: Write an R program that prints three lines Correct Answer: print('I can program in R!') print('I can program in Python!') print('I can program in at least 2 languages! Can you?') Rationale: Each print() statement produces one line of output. Multiple commands can be placed on separate lines in an R script and executed sequentially.
  4. Basics of R: Is R case-sensitive? Correct Answer: Yes. Rationale: R distinguishes between uppercase and lowercase characters. For example, Data, data, and DATA are treated as different names.
  5. Basics of R: How can you separate R commands? Correct Answer: Using a semi-colon or a newline. Rationale: R allows commands to be separated by new lines. A semicolon can also explicitly separate multiple commands on the same line.
  1. Basics of R: How are commands grouped together in R? Correct Answer: Using brackets { }. Rationale: Curly braces group multiple statements into a code block, particularly within functions, loops, and conditional statements.
  2. Basic Syntax of R: How do you comment in R? Correct Answer: Using a # symbol. Rationale: Text following # on a line is treated as a comment rather than executable code. Comments document code and improve readability.
  3. Basic Syntax of R: How are variables assigned in R? Correct Answer: Using the <- symbol. Rationale: The <- operator is the conventional assignment operator in R and associates a value with a variable name.
  4. Basic Syntax of R: How can you get help for any function in R? Correct Answer: Using help(function) or ?function. Rationale: R provides built-in documentation for functions. For example, help(mean) or ?mean displays information about the mean() function.
  5. Calculations in R: What are the standard math operators in R? Correct Answer: *+, - , , /, ^ (power). Rationale: These operators perform addition, subtraction, multiplication, division, and exponentiation in R.
  6. Calculations in R: What are some predefined trigonometric functions in R? Correct Answer: sin, cos, tan. Rationale: R includes built-in trigonometric functions such as sin(), cos(), and tan() for mathematical and statistical calculations.
  1. A single-line comment starts with #. Correct Answer: True. Rationale: The # symbol tells R to treat the remaining text on that line as a comment.
  2. The = is the preferred syntax for variable assignment. Correct Answer: False. Rationale: Although = can be used for assignment in many situations, <- is the conventional and preferred assignment operator in R programming.
  3. What is a numeric data type? Correct Answer: Decimal values, integer, complex. Rationale: Numeric data represent quantitative values. R supports numeric values and also has distinct integer and complex representations.
  4. What is a character data type? Correct Answer: String values denoted with single or double quotes. Rationale: Character data represent text. R recognizes quoted text such as 'Hello' or "Hello" as character strings.
  5. Make a comment with your name and student number. Correct Answer: N/A. Rationale: This is an individualized programming exercise. A suitable R comment would begin with #, followed by the requested information.
  6. Calculate 45 - 12^3. Correct Answer: - 1708. Rationale: Following operator precedence, 12^3 = 1728 , 45 = 20 , and therefore 20 - 1728 = - 1708. The supplied answer of - 1724 does not match the standard R calculation.
  1. Calculate e^4*3. Correct Answer: N/A. Rationale: In R, exponentiation involving Euler's number is normally written using exp(). For example, exp(4) * 3 calculates three times e to the fourth power.
  2. Calculate sin(4pi - 6). Correct Answer: N/A. Rationale: R evaluates sin() using radians. The expression sin(4pi - 6) can be entered directly into R to obtain the numerical result.
  3. What are the variable types? Correct Answer: var1 = logical, var2 = logical, var3 = numeric, var4 = character. Rationale: R supports multiple data types. Logical values represent TRUE/FALSE conditions, numeric values represent numbers, and character values represent text.
  4. What are the comparison operators in R? Correct Answer: >, >=, <, <=, ==, !=. Rationale: Comparison operators evaluate relationships between values and return logical results of TRUE or FALSE.
  5. What is the greater-than operator? Correct Answer: >. Rationale: The > operator evaluates whether the value on its left is greater than the value on its right.
  6. What is the greater-than-or-equal operator? Correct Answer: >=. Rationale: The >= operator returns TRUE when the left value is greater than or equal to the right value.

Correct Answer: !. Rationale: The! operator reverses a logical value: TRUE becomes FALSE and FALSE becomes TRUE.

  1. What are decisions in programming? Correct Answer: Actions based on conditions. Rationale: Decision structures allow a program to execute different instructions depending on whether specified conditions are TRUE or FALSE.
  2. What is the syntax for if statements in R? Correct Answer: if (condition) { statements } Rationale: An if statement evaluates a logical condition and executes the statements inside the braces when the condition evaluates to TRUE.
  3. What happens if the condition in an if statement is TRUE? Correct Answer: The statement after the if condition is performed. Rationale: When the condition evaluates to TRUE, R executes the code contained within the corresponding if block.
  4. What happens if the condition in an if statement is FALSE? Correct Answer: If there is an else, the statement after the else is performed. Rationale: When an if condition is FALSE, R skips its block and executes the else block when one is provided.
  5. What is the recommended indentation for if statements? Correct Answer: Indentation is recommended but not required. Rationale: R does not require indentation for syntax, but consistent indentation makes conditional code easier to read, understand, and maintain.
  6. What is the syntax for if/else if statements?

Correct Answer: if (condition) { statement } else if (condition) { statement } else if (condition) { statement } else { statement } Rationale: This structure allows R to evaluate multiple conditions in sequence. The first condition that evaluates to TRUE determines which block is executed.

  1. What is the syntax for a for loop in R? Correct Answer: for (i in seq(1,10,1)) { print(i) } Rationale: A for loop repeatedly executes a block of code for each value in a specified sequence. Here, i takes values from 1 through 10.
  2. How do you define and call a function in R? Correct Answer: Function Name, function Keyword, Parameter Name n = 20, Call function by Argument print(doubleNum(n)). Rationale: An R function is defined using the function keyword, accepts parameters, performs specified operations, and can return a value. It is then called using the function name and appropriate arguments.
  3. What does the doubleNum function in R do? Correct Answer: Doubles the input number and returns it. Rationale: A function named doubleNum would typically multiply its input by 2 and return the resulting value.
  4. What is the modulus operator in R? Correct Answer: %%. Rationale: The %% operator returns the remainder after integer division. It is useful for determining whether values divide evenly or identifying repeating patterns.
  5. What is the purpose of the read.table function in R? Correct Answer: Reads delimited data from a file. Rationale: read.table() imports tabular data from external files into R, allowing the imported information to be analyzed as a data frame.
  1. How do you use the head() function to show a specific number of rows? Correct Answer: head(data, 10) # First 10 rows Rationale: The second argument specifies how many rows should be returned. Therefore, head(data, 10) displays the first ten observations.
  2. How do you use the tail() function to show a specific number of rows? Correct Answer: tail(data, 20) # Last 20 rows Rationale: The second argument specifies the number of observations to return from the end of the dataset.
  3. What is the purpose of the seq() function in R? Correct Answer: Generates a sequence of numbers. Rationale: seq() creates regularly spaced sequences and is commonly used for iteration, indexing, and generating numeric values.
  4. What is the purpose of the print() function in R? Correct Answer: Prints the specified value. Rationale: print() displays an object's value or text in the Console.
  5. What is the purpose of the paste() function in R? Correct Answer: Concatenates strings. Rationale: paste() combines character strings into larger strings and can insert separators between the components.
  6. What is the purpose of the return keyword in R? Correct Answer: Returns a value from a function. Rationale: return() explicitly specifies the value a function should return. Although R can implicitly return the final evaluated expression, return() can make the intended output explicit.
  1. What is the purpose of the header parameter in the read.table and read.csv functions? Correct Answer: Specifies whether the first row of the data set is used for variable names. Rationale: Setting header=TRUE tells R that the first row contains column names rather than ordinary observations.
  2. What are vectors in R? Correct Answer: Indexed list of data of any one type. Rationale: An R vector is a one-dimensional collection whose elements generally share a common basic data type. Vectors are fundamental structures used throughout R.
  3. How can you create vectors in R? Correct Answer: Using colon or seq() function. Rationale: The colon operator can generate simple sequences, while seq() provides greater control over starting value, ending value, and increments.
  4. What is the syntax for creating a vector using colon? Correct Answer: start:end. Rationale: The colon operator generates a sequence from the starting value through the ending value, usually in increments of one.
  5. What is the syntax for creating a vector using seq()? Correct Answer: seq(start, end, by). Rationale: seq() allows the user to specify the starting point, ending point, and increment between values.
  6. How can you create an empty vector in R? Correct Answer: Using c() function. Rationale: The c() function combines values into a vector. Calling c() without arguments creates an empty vector.