Modules 10-21: Correlation and Bootstrap

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Listen to an AI-generated conversation about this lesson
Download our mobile app to listen on the go
Get App

Questions and Answers

In the context of correlation analysis, what crucial condition must be satisfied to ensure the accurate application and interpretation of the cor(x, y) function?

  • The relationship between x and y must be perfectly non-linear.
  • The data must be categorical.
  • The data should contain outliers.
  • The relationship between x and y must be linear. (correct)

What is the primary purpose of using jitter plots when visualizing data?

  • To calculate the correlation coefficient between two quantitative variables.
  • To reduce the number of observations in a dataset.
  • To eliminate outliers from a dataset.
  • To smear categorical data points for better visualization of data density. (correct)

What is the primary purpose of the table(x, y) function in statistical analysis using R?

  • To compute the frequency of each pair of responses between two variables. (correct)
  • To fit a linear regression model.
  • To calculate the correlation between two variables x and y.
  • To create a jitter plot for visualizing categorical data.

In the context of bootstrapping, what is the critical characteristic of the sampling process?

<p>Sampling with replacement to mimic the original dataset's distribution. (A)</p>
Signup and view all the answers

What is the main purpose of performing a permutation test for correlation?

<p>To assess the statistical significance of an observed correlation by randomizing one variable. (A)</p>
Signup and view all the answers

What is the role of complete.cases() in data preparation for statistical analysis?

<p>It removes all rows with missing values to ensure complete data for analysis. (D)</p>
Signup and view all the answers

What does the corrplot function with method = "ellipse" primarily visualize?

<p>The direction and strength of correlations between multiple variables. (A)</p>
Signup and view all the answers

In the context of regression analysis, what is the primary purpose of examining residual plots?

<p>To assess whether the assumptions of linear regression, such as normality and homoscedasticity, are met. (A)</p>
Signup and view all the answers

When performing bootstrap for a quadratic model, what is the key advantage of using a bootstrap confidence interval compared to a theoretical confidence interval?

<p>The bootstrap confidence interval is wider and more robust, especially when assumptions are violated. (B)</p>
Signup and view all the answers

In regression analysis, what is the key distinction between a prediction band and a confidence band?

<p>A prediction band provides an interval for a single future observation, whereas a confidence band estimates the average response. (D)</p>
Signup and view all the answers

What is the primary reason that influential points and outliers can significantly affect a regression model?

<p>They can disproportionately alter the slope and intercept of the regression line. (B)</p>
Signup and view all the answers

Why is it important to address heteroskedasticity in a regression model?

<p>Because it violates the assumption of constant variance of residuals, affecting the reliability of statistical tests. (B)</p>
Signup and view all the answers

What is the purpose of using the gsub function in the expression gsub("\\?\\*", "", guns_death$Country)?

<p>To remove any occurrence of '?' or '*' characters from the <code>guns_death$Country</code> column. (D)</p>
Signup and view all the answers

In the context of multiple regression, what does multicollinearity refer to, and why is it a concern?

<p>High correlation among predictor variables, which can inflate standard errors and destabilize coefficient estimates. (C)</p>
Signup and view all the answers

In the context of model selection in multiple regression, what is the primary purpose of using Adjusted R-squared over regular R-squared?

<p>Adjusted R-squared penalizes the inclusion of unnecessary predictors, providing a more accurate measure of model fit. (C)</p>
Signup and view all the answers

In multiple regression, what is one of the key assumptions regarding the nature of the predictor variables?

<p>Predictors should not be correlated with each other. (B)</p>
Signup and view all the answers

When using categorical predictors in a regression model, how does R handle the inclusion of these variables by default?

<p>R automatically creates dummy variables and sets one level of each categorical variable as the reference. (C)</p>
Signup and view all the answers

What is the primary purpose of the Box-Cox transformation?

<p>To transform the response variable in a regression model to better meet normality and homoscedasticity assumptions. (D)</p>
Signup and view all the answers

In the context of ANOVA, what does the F-statistic primarily test?

<p>The equality of means across different groups. (B)</p>
Signup and view all the answers

In a two-way ANOVA, what does a significant interaction effect indicate?

<p>That the effects of one factor depend on the level of the other factor. (B)</p>
Signup and view all the answers

In the context of linear regression, what is the fundamental assumption regarding the error terms ($\epsilon_i$)?

<p>$\epsilon_i$ are assumed to be independent and identically distributed random variables from a normal distribution with mean zero and constant standard deviation. (D)</p>
Signup and view all the answers

Consider a scenario where you aim to estimate the parameters $\beta_0$, $\beta_1$, and $\sigma$ in a simple linear regression model. What does $\sigma$ specifically represent?

<p>The true standard deviation of the errors. (A)</p>
Signup and view all the answers

In the context of interpreting coefficients in a linear regression model, what does the intercept represent?

<p>The predicted value of the dependent variable when all continuous predictors are equal to 0, and all categorical predictors are at their reference category. (A)</p>
Signup and view all the answers

When interpreting a coefficient for a continuous predictor (e.g., V241324) in a linear regression model, what does the coefficient signify?

<p>A 1-point increase in the independent variable corresponds to a $\beta$ point change in the dependent variable, holding all other variables constant. (A)</p>
Signup and view all the answers

In the context of interpreting coefficients for categorical predictors (e.g., V241227x, Party ID) in a regression model, what do these coefficients represent?

<p>Coefficients represent the difference in outcome between each category and the baseline (reference) category, usually Independent. (D)</p>
Signup and view all the answers

What is the primary difference between a prediction interval and a confidence interval in the context of regression analysis?

<p>A prediction interval estimates a single value of the dependent variable, while a confidence interval estimates a population parameter. (D)</p>
Signup and view all the answers

In the context of interaction effects in a two-way ANOVA, what does a significant interaction indicate?

<p>The effects of one factor depend on the level of the other factor. (A)</p>
Signup and view all the answers

What is the purpose of the Box-Cox transformation in the context of regression analysis?

<p>To transform the dependent variable to better meet the assumptions of linear regression, such as normality and homoscedasticity. (D)</p>
Signup and view all the answers

In the context of best subset selection in regression, what is a key consideration when evaluating different models?

<p>Balancing model complexity with goodness of fit, often using metrics like AIC or BIC. (C)</p>
Signup and view all the answers

What is the purpose of Tukey's Honestly Significant Difference (HSD) test?

<p>To perform post-hoc pairwise comparisons between group means after an ANOVA to control for the family-wise error rate. (A)</p>
Signup and view all the answers

In forward stepwise regression, what criterion is typically used to determine which variable to add to the model at each step?

<p>The variable that results in the largest decrease in the Akaike Information Criterion (AIC) or Bayesian Information Criterion (BIC). (B)</p>
Signup and view all the answers

In backward stepwise regression, what criterion is typically used to determine which variable to remove from the model at each step?

<p>The variable that results in the largest increase in the Akaike Information Criterion (AIC) or Bayesian Information Criterion (BIC). (B)</p>
Signup and view all the answers

What is the primary purpose of the Akaike Information Criterion (AIC) in model selection?

<p>To balance the goodness of fit of a model with its complexity, penalizing models with more parameters. (D)</p>
Signup and view all the answers

What is heteroskedasticity, and why is it a concern in regression analysis?

<p>Heteroskedasticity refers to non-constant variance of error terms, leading to inefficient and potentially biased estimates of standard errors. (B)</p>
Signup and view all the answers

How does Pearson's product-moment correlation coefficient measure the relationship between two variables?

<p>It measures the strength and direction of a linear relationship between two continuous variables. (C)</p>
Signup and view all the answers

In the context of ANOVA, what is the key difference between Type II and Type III sums of squares?

<p>Type II sums of squares assess the significance of each factor controlling for all other factors, while Type III sums of squares assess the significance of each factor ignoring all other factors. (C)</p>
Signup and view all the answers

What is the purpose of Bartlett's test in the context of ANOVA?

<p>To test for homogeneity of variances across groups. (C)</p>
Signup and view all the answers

Under what conditions might Welch's ANOVA be preferred over a standard ANOVA?

<p>When the assumption of homogeneity of variances is violated. (D)</p>
Signup and view all the answers

What type of data is Kruskal-Wallis test most appropriate for?

<p>Non-normally distributed ordinal or continuous data (D)</p>
Signup and view all the answers

In a two-way ANOVA, how do you interpret an interaction plot?

<p>Intersecting or non-parallel lines suggest an interaction between factors. (B)</p>
Signup and view all the answers

What does the 'Total SS' (Sum of Squares) represent in the context of ANOVA?

<p>The sum of the squared differences between each individual data point and the grand mean. (C)</p>
Signup and view all the answers

How does increasing the confidence level affect the width of a confidence interval?

<p>It increases the width of the confidence interval. (B)</p>
Signup and view all the answers

When interpreting the standard error, what does it primarily quantify?

<p>The variability of the sample statistic. (A)</p>
Signup and view all the answers

How does Levene's test assess the equality of variances across groups?

<p>By comparing the spread of the data points within each group around there centre. (B)</p>
Signup and view all the answers

What is the relationship between variance and standard deviation?

<p>Variance is the square of the standard deviation. (A)</p>
Signup and view all the answers

For a regression model, suppose you want to test the overall significance, which statistical test should be used?

<p>F-test (A)</p>
Signup and view all the answers

In linear regression, what is the effect of adding an irrelevant variable to the model?

<p>Increase the R-squared, but the adjusted R-squared might decrease. (B)</p>
Signup and view all the answers

What term describes the condition when predictor variables in a regression model are highly correlated with each other?

<p>Multicollinearity (B)</p>
Signup and view all the answers

Which of these is not a method to address heteroscedasticity in a regression model?

<p>Add more predictor variables. (D)</p>
Signup and view all the answers

When performing a two-way ANOVA, what is the difference between a main effect and an interaction effect?

<p>A main effect represents the effect of one independent variable averaging over all levelcs of the other independent variable, while an interaction effect represents whether the effect of one IV depends on the level of the other IV. (B)</p>
Signup and view all the answers

What is the assumption required for ANOVA?

<p>All of the above (D)</p>
Signup and view all the answers

What is the meaning of degree of freedom?

<p>Indicates the number of categories in data that are free to vary given certain constraints (C)</p>
Signup and view all the answers

What does a confidence interval estimate?

<p>A range of values that likely contains the population parameter with a certain level of certainty. (A)</p>
Signup and view all the answers

In what condition should you use Welch's ANOVA?

<p>When the variances are not equal across groups. (C)</p>
Signup and view all the answers

What is the primary reason one might choose to use the Kruskal-Wallis test?

<p>To compare three or more groups when the data are not normally distributed. (D)</p>
Signup and view all the answers

Among R-squared and Adjust R-squared, which measurement is better to use when increasing predictors?

<p>Adjusted R-squared, because it can decrease when adding a new NON-significant predictor. (B)</p>
Signup and view all the answers

How is Total SS calculated in the context of ANOVA?

<p>Add the squared difference between each data point and grand mean. (A)</p>
Signup and view all the answers

Which test is a post-hoc test to determine which population mean differ after we have already run ANOVA and determined our F-statistic is significant.

<p>Tukey's Honestly Significant Difference test (C)</p>
Signup and view all the answers

In the context of linear regression, what does the assumption $\epsilon_i \sim N(0, \sigma)$ imply about the error terms?

<p>The errors are normally distributed with a mean of 0 and a constant standard deviation of $\sigma$. (B)</p>
Signup and view all the answers

In a linear regression model, the coefficient for a continuous predictor (e.g., V241324) is 0.5. How should this coefficient be interpreted?

<p>For every one-unit increase in V241324, the dependent variable is predicted to increase by 0.5 units, holding all other variables constant. (C)</p>
Signup and view all the answers

In the output of a linear regression model, what does a statistically significant coefficient for a categorical predictor (e.g., V241227x) indicate?

<p>It indicates a significant difference in the mean of the dependent variable between that category and the reference category, holding all other variables constant. (B)</p>
Signup and view all the answers

In the context of multiple R-squared and Adjusted R-squared, what is the key benefit of using Adjusted R-squared when evaluating regression models with different numbers of predictors?

<p>Adjusted R-squared accounts for the increase in variance explained by adding more predictors and penalizes the inclusion of irrelevant predictors, providing a more accurate measure of goodness-of-fit. (A)</p>
Signup and view all the answers

What is the primary purpose of performing a Box-Cox transformation on the response variable in a linear regression model?

<p>To transform non-normal error terms into normally distributed error terms, satisfying one of the assumptions of linear regression. (C)</p>
Signup and view all the answers

In the context of analyzing the output of an ANOVA, what does a significant F-statistic suggest about the means of the groups being compared?

<p>At least one of the group means is significantly different from the others. (D)</p>
Signup and view all the answers

In the context of a two-way ANOVA, how should a significant interaction effect between two factors be interpreted?

<p>The effect of one factor on the response variable depends on the level of the other factor. (D)</p>
Signup and view all the answers

What is the utility of Tukey's Honestly Significant Difference (HSD) test following an ANOVA?

<p>To identify which specific group means are significantly different from each other after a significant F-test. (A)</p>
Signup and view all the answers

In forward stepwise regression, what criterion is typically used to determine which predictor variable to add to the model at each step?

<p>The variable that results in the largest decrease in the Akaike Information Criterion (AIC). (A)</p>
Signup and view all the answers

In backward stepwise regression, what is the variable selection criteria?

<p>Variable with the highest p-value. (C)</p>
Signup and view all the answers

What is the primary goal of the Akaike Information Criterion (AIC) in model selection?

<p>To balance the goodness-of-fit of the model with its complexity, penalizing models with more parameters. (D)</p>
Signup and view all the answers

What does Bartlett's test assess in the context of ANOVA?

<p>The equality of variances across groups. (C)</p>
Signup and view all the answers

Under what specific conditions is Welch's ANOVA preferred over a standard ANOVA?

<p>When the assumption of homogeneity of variances is violated. (A)</p>
Signup and view all the answers

What is the most crucial condition for accurately applying and interpreting Pearson's product-moment correlation coefficient?

<p>The relationship between the variables must be linear. (C)</p>
Signup and view all the answers

In the context of ANOVA, what differentiates Type II Sums of Squares from Type III Sums of Squares?

<p>Type II SS tests each factor assuming all other factors are uncorrelated, while Type III SS tests each factor adjusting for all other factors in the model. (C)</p>
Signup and view all the answers

How might increasing the confidence level (e.g., from 95% to 99%) affect the width of a confidence interval, assuming all other factors remain constant?

<p>It will increase the width of the confidence interval. (C)</p>
Signup and view all the answers

How should a statistically significant interaction effect in a two-way ANOVA be visually assessed and confirmed?

<p>By creating an interaction plot to visualize how the effect of one factor varies across the levels of the other factor. (A)</p>
Signup and view all the answers

What can be inferred about individual group differences when the Kruskal-Wallis test yields a statistically significant result?

<p>At least one group is significantly different from the other groups. (A)</p>
Signup and view all the answers

In ANOVA, what does the 'Total SS' (Sum of Squares) represent, and how is it calculated?

<p>It represents the total variability in the data and is calculated as the sum of squared differences between each data point and the overall (grand) mean. (C)</p>
Signup and view all the answers

When should the Kruskal-Wallis test be employed instead of a one-way ANOVA, and what type of data is it most suitable for?

<p>When the data are not normally distributed or the variances are unequal across groups; it is suitable for ordinal or continuous data that do not meet ANOVA assumptions. (D)</p>
Signup and view all the answers

In linear regression, how does adding an irrelevant variable to the model typically affect the residual sum of squares (RSS) and the model's overall performance?

<p>The RSS will decrease slightly, but the model's performance, as measured by adjusted R-squared, may worsen due to overfitting. (A)</p>
Signup and view all the answers

When interpreting the standard error, what does it primarily quantify, and how does it relate to the precision of parameter estimates?

<p>It quantifies the variability of sample statistics (such as the sample mean) and provides a measure of the precision with which a population parameter is estimated. (A)</p>
Signup and view all the answers

Which of the following transformations is LEAST likely to address heteroscedasticity in a regression model?

<p>Adding a quadratic term for one of the predictors. (A)</p>
Signup and view all the answers

How does Levene's test assess the equality of variances across groups, and what is its primary advantage over other tests like Bartlett's test?

<p>Levene's test assesses the equality of variances and is more robust to departures from normality than Bartlett's test. (A)</p>
Signup and view all the answers

What is the relationship between variance and standard deviation, and how does understanding this relationship aid in interpreting statistical results?

<p>Standard deviation is the square root of the variance, and it provides a measure of the average distance of data points from the mean, expressed in the original units of measurement. (B)</p>
Signup and view all the answers

Why is careful consideration of predictor variables crucial in multiple regression?

<p>The variables might have underlying interactions or may cause multicollinearity. (C)</p>
Signup and view all the answers

In linear regression, what condition would make the intercept $\beta_0$ uninterpretable?

<p>If the value of zero on the predictor variables does not have a practical meaning. (C)</p>
Signup and view all the answers

In an ANOVA, what does a large mean square between groups (MSG) relative to the mean square within groups (MSW) suggest?

<p>There is significant variation between the groups compared to the variation within the groups. (C)</p>
Signup and view all the answers

What is the impact of failing to meet the homogeneity of variances assumption in ANOVA, and what are some potential remedies?

<p>It invalidates the F-test, but can be remedied by using Welch's ANOVA or transforming the data. (A)</p>
Signup and view all the answers

Why is visualizing interaction effects essential in a two-way ANOVA, and what can interaction plots reveal that numerical outputs alone cannot?

<p>Interaction plots provide a visual representation of how the effect of one factor changes across the levels of another factor, revealing patterns and complexities that are not immediately apparent from numerical summaries. (D)</p>
Signup and view all the answers

In regression analysis, what are prediction bands, and how do they differ fundamentally from confidence bands?

<p>Prediction bands estimate the uncertainty in predicting a new observation, while confidence bands estimate the uncertainty in the mean response at a given value of the predictor variables. (D)</p>
Signup and view all the answers

What is multicollinearity, and what is its primary impact on the interpretation of regression coefficients?

<p>It describes the variables themselves being highly correlated preventing the model from identifying the individual effects. (A)</p>
Signup and view all the answers

In linear regression, what is the role of residual plots in assessing the validity of model assumptions?

<p>Residual plots helps detect patterns in residuals, such as non-linearity or heteroskedasticity, indicating violations of the model's assumptions about error term. (C)</p>
Signup and view all the answers

What is the first step one should do when preparing to analyze the data?

<p>Prepare the data. (B)</p>
Signup and view all the answers

In the expression, Yi = β0 + β1Xi + εi, what does εi represent, and what assumptions do we typically make about its distribution in linear regression?

<p><code>εi</code> represents the random error term, and we assume it follows a normal distribution with a mean of zero and constant variance. (B)</p>
Signup and view all the answers

Flashcards

cor(x,y)

Calculates the correlation between two variables, ranging from 0 to 1. Only use when the relationship is linear.

Correlation

Strength of the linear relationship between two quantitative variables.

Jitter Plots

Smears categorical data in a plot so we can see the density of observations.

table(x,y)

Calculates the frequency of each pair of responses in a dataset.

Signup and view all the flashcards

Bootstrapping

Resampling data with replacement to estimate variability.

Signup and view all the flashcards

Permutation Test for Correlation

A statistical test to determine if the correlation between two variables is significant.

Signup and view all the flashcards

WB2 <- WB2[complete.cases(WB2), ]

Changes the dataset to only include complete entries for variables, removing rows with NA values.

Signup and view all the flashcards

cor(WB2[,-1])

Gives the correlation between all columns of a data frame.

Signup and view all the flashcards

corrplot

Visualizes the direction and strength of correlations using ellipses.

Signup and view all the flashcards

Matrix Plot

A visual tool to check for linear relationships between multiple variables.

Signup and view all the flashcards

Theoretical regression model

A line that best fits the average relationship between two variables.

Signup and view all the flashcards

na.omit()

Removes rows with missing values from a dataset.

Signup and view all the flashcards

Confidence intervals

Gives intervals of the slope of a regression line

Signup and view all the flashcards

Quadratic Model

Adds a curve to a plot to represent a quadratic relationship.

Signup and view all the flashcards

Prediction Band

Estimate the 95% interval for a single data point.

Signup and view all the flashcards

Confidence Band

Estimate the 95% interval for a regression line.

Signup and view all the flashcards

Influential Points

Influential points and outliers that can disproportionately affect the regression line.

Signup and view all the flashcards

Cooks distance

Points with a larger value on regression lines

Signup and view all the flashcards

Heteroskedasticity

Where the standard deviation of residuals is not constant

Signup and view all the flashcards

normal quantile plot

In log is not normal

Signup and view all the flashcards

Multiple R-squared

A measure of how well a linear regression model fits the observed data, representing the proportion of variance in the dependent variable explained by the independent variables.

Signup and view all the flashcards

Forward Stepwise Regression

A stepwise regression technique that starts with no predictors and adds them one at a time based on which improves the model fit the most.

Signup and view all the flashcards

Backward Stepwise Regression

A stepwise regression technique that starts with all potential predictors and removes them one at a time based on which has the least impact on the model fit.

Signup and view all the flashcards

Akaike Information Criterion (AIC)

A criterion for model selection that balances model fit and complexity, penalizing models with more parameters.

Signup and view all the flashcards

Pearson's Product-Moment Correlation

A measure of the strength and direction of the linear relationship between two variables.

Signup and view all the flashcards

ANOVA Type 3

Testing effects of variables in ANOVA

Signup and view all the flashcards

ANOVA Type 2

Testing effects of variables in ANOVA

Signup and view all the flashcards

ANOVA

A statistical test used to compare the means of two or more groups.

Signup and view all the flashcards

Bartlett's Test

Checking the equality of variances within groups

Signup and view all the flashcards

Levene's Test

Test for equality of variances of groups

Signup and view all the flashcards

Welch's ANOVA

An alternative to ANOVA when the assumption of equal variances is violated.

Signup and view all the flashcards

Kruskal-Wallis Test

A non-parametric test used to compare the means of two or more groups when the data are not normally distributed.

Signup and view all the flashcards

Two-Way ANOVA

An ANOVA used to study the effects of two or more independent variables on a dependent variable.

Signup and view all the flashcards

Interaction Plot

A plot used to visualize the interaction effects between two or more independent variables in an ANOVA.

Signup and view all the flashcards

Total SS (Sum of Squares)

The sum of squares representing the overall variability in the data.

Signup and view all the flashcards

Interpreting ANOVA

Assessing the statistical significance and practical importance of the results obtained from an ANOVA test.

Signup and view all the flashcards

Interpreting Standard Error

A measure of the variability of the sample mean, indicating the precision of the estimate.

Signup and view all the flashcards

Box-Cox Transformation

A transformation applied to non-normal data to make it more closely approximate a normal distribution, which is required for many statistical tests.

Signup and view all the flashcards

Best Model Subset

Process of selecting the best subset of predictors for a regression model based on various fit statistics.

Signup and view all the flashcards

Tukey's Honestly Significant Difference (HSD) Test

A post-hoc test used in ANOVA to determine which group means are significantly different from each other.

Signup and view all the flashcards

Intercept in Regression

The predicted value of outcome when all continuous predictors are zero, and all categorical predictors are at their reference category

Signup and view all the flashcards

Regression Coefficient

Indicates the change in the outcome variable associated with a one-unit increase in the predictor, holding all other variables constant

Signup and view all the flashcards

Study Notes

Module 10: Correlation and Bootstrap

  • cor(x,y) calculates the correlation between 0 and 1; only use when the relationship is linear.
  • Correlation is the strength of the linear relationship between two quantitative variables.
  • Jitter plots smear categorical data, on a quantitative scale, to visualize the density of observations at each intersection of values, using plot(jitter(x, factor=1), jitter(y)).
  • table(x,y) calculates the frequency of each pair of responses.
  • The frequency of a table can be turned into a size-proportional scatterplot by assigning freq <- c(table(x,y)), then plotting with plot(x, y, cex = sqrt(freq)), and superimposing frequencies text(x, y, freq).
  • Bootstrapping correlation and regression slopes involves calculating the correlation cor1 <- cor(x,y), testing if the correlation is nonzero cor.test(x,y), fitting a linear regression model lm1 <- lm(x~y), and extracting coefficients of the line lm1$coef which returns the intercept and slope.
  • Bootstrapping is done by sampling rows with replacement from the original dataset, ensuring the same number of observations, then calculating the correlation and slope for the "fake" dataset to determine confidence intervals.

Module 11: Correlation, Permutations, Multiple

  • The Permutation Test assesses correlation by checking the p-value cor.test(cry$Crying, cry$IQ).
  • Outliers can artificially inflate correlations; so a permutation test is performed where one variable is permuted and then recalculated.
  • To use the permutation test first permute one variable fakeIQ = sample(IQ) then bind the natural order cbind(crying, IQ) and the random order cbind(crying, fakeIQ).
  • The p-value, representing the likelihood of observing the true correlation if there is no association, is then calculated.
  • To make CorResults for the permutation test assign a number of samples, for example, 10000, by setting corResults <- rep(NA, n-samp).
  • To test for correlation run a loop where: for (i in n-samp) { corResults [i] <-cor(crying, sample (IQ)) }.
  • Calculate a 2-sided p-value for fake correlations by finding the tme cor <- mean(abs(corResults) >= abs(cor(crying, IQ))).
  • WB2 <- WB2[complete.cases(WB2), ] changes the dataset to include complete entries for variables
  • cor(WB2[,-1]) outputs correlations between all columns, made easier to visualize in a plot.
  • corrplot(cor(WB2[,-1]), method = "ellipse") generates a plot displaying the direction and strength of correlations.
  • Matrix plots can be used to to check for linearity with multiple scatterplots plot(WB2[,-1]).
  • Taking the log may help linearize data.
  • Other methods include chart.Correlation(WB2[,-1]), corrplot.mixed(cor(WB2[,-1]), ...other modifiers...).
  • Pearson Product-Moment Correlation is calculated using cor.test(ctTEMP$Min, ctTEMP$Year).

Module 12: Regression

  • The theoretical regression model is My = Bo + B₁X.
  • The actual values are represented as Y₁ = Bo + B₁X₁ + Eᵢ, where there are independent observations from a normal distribution with a mean of 0 and some common standard deviation.
  • Before performing regressions, verify the assumptions of linearity and normal distribution of errors.
  • To account for missing values use code like crosby <- na.omit(crosby).
  • To fit the model you can use lm1 <- lm(Mintemp ~ Year).
  • To show coefficients of line you can use lm1$coefficients.
  • You can find the confidence interval for the true slope using confint(lm1, 'Year').
  • You can also use bootstrapping here, sample with replacement, calculates a new correlation, saves scores into a vector, and get a CI of those scores.
  • The boot CI will be wider than the theoretical CI.
  • Quadratic Models can be create using the code lm2 <- lm(y ~ x + x^2) and adding a curve to the plot using the code points(x, lm2$fitted.values, type = "l").
  • For bootstrapping quadratics begin with finding the number of rows using N <- nrow(data).
  • You can use the code bResults <- matrix(rep(NA, 3*n-samp), ncol = 3) to create a matrix.
  • You can use the code S <- sample(1:N, N, replace = T) to get a sample. Assign the fake year fakeYear <- Year[s] and the fake year squared fakeYearSq <- fakeYear^2, and the fake temp fakeTemp <- Mintemp[s].
  • The code lmtemp <- lm(fakeTemp ~ fakeYear + fakeYearSq) can get the results bResults[i,] <- lmtemp$coef.
  • Finally get the get the CI using the code ci-line <- quantile(bResults[,2], c(.025,.975)) and ci-quad <- quantile(bResults[,3], c(.025,.975)).
  • Linear regression aims to find the best-fitting line (or hyperplane) that models the relationship between a dependent variable 𝑌 and one or more independent variables 𝑋
  • The observed values of 𝑌 are equal to the mean function plus a random error: 𝑌𝑖=𝛽0+𝛽1𝑋𝑖+𝜀𝑖
  • The errors 𝜀𝑖 are assumed to be independent and identically distributed random variables from a normal distribution with mean zero and constant standard deviation: 𝜀𝑖∼𝑁(0,𝜎)
  • The aim is to estimate the following unknown parameters: 𝛽0,𝛽1,𝜎, where 𝛽0 is the true intercept, 𝛽1 is the true slope, and 𝜎 is the true standard deviation of the errors.

Module 13: Regression 2

  • For a 95% confidence interval for average minimum temp in 2100, a prediction band is needed, which is wider than confidence intervals since it accounts for the range of potential individual data points.
  • For a 95% confidence interval for the regression line in year 2100, use a confidence band.
  • 95% confidence means the regression line is between blue lines.
  • 95% confidence means all future data will fall between the red lines.
  • R-squared measures the proportion of variance in y explained by the regression model.
  • Influential points and outliers (large residuals) can affect the regression line.
  • Cook's distance quantifies the influence of a data point; a larger value indicates greater influence.
  • Standardized residuals are calculated as the residual divided by the sample SD.
  • Heteroskedasticity exists if the standard deviation of residuals is non-constant.
  • Use a transformation to deal with heteroskedasticity by making ln() or sqrt() transformations; look for a fanning pattern in the residual spread.
  • Add a regression line to a plot using abline(lm1$coef, lwd = 3).
  • New temperatures can be predicted until 2100 using the code newyear <- seq(min(Year), 2100, by=1) and assigning the data frame nd <- data.frame(Year = newYear).
  • Use the code confbands2 <- predict(lm1, interval = "confidence", newdata=nd) and predbands1 <- predict(lm1, interval = "prediction", newdata=nd) to get results.
  • The code plot(mod1, which=4) generates a plot of Cook's distance.
  • The code text(x,y, vector of text to show, pos = 1) superimposes text on points.
  • Create a normal quantile plot using the function qqPlot(rstudent(lm1)) which generates a norm-a plot of studentized residuals.
  • Good visualization will result in no pattern.
  • Using the library olsrr can give useful residual plots.

Module 16: Multiple Regression and Continuous Predictors

  • In multiple regression, the theoretical model equation: Y = Bo + B₁X₁ + B₂X₂ +...+BₙXₙ.
  • Bₙ represents the change in Y for every unit increase in Xₙ; there are three assumptions: linearity, constant variance, and the predictors are not strongly correlated.
  • Predicted values are calculated ŷᵢ = b₀ + b₁X₁ + b₂X₂ + ... + bₙXₙ, and residuals are calculated eᵢ = Yᵢ - ŷᵢ.
  • Multiple R² indicates the amount of variability in Y explained by multiple regression.
  • Forward stepwise regression aims to create a simpler model by starting with the best predictor and iteratively adding significant predictors.
  • R² value always increases when more are added, which is a problem.
  • Adjusted R² adds a penalty for the number of terms; always less than R² use Adjusted R² .
  • Akaike Information Criterion is useful for smaller models and is only used when comparing different models.
  • Cp statistic helps identify the simplest model.

Module 18: Multiple Regression and Categorical Predictors

  • Assesses whether things are getting warmer over time by checking if in regression slope > 0
  • Variables may be categorical and non-orderable.
  • R automatically creates reference variables, omitting one level of each categorical variable from the model.
  • Assumptions of heteroskedasticity are tested; you can do Box-Cox transformation if assumptions are not met.
  • levels(var) displays the levels of a variable.
  • Multiple boxplots can be displayed boxplot(TMIN ~ Month, data = ctTEMP).
  • Code to Change order of levels includes steps such as levels (ctTEMP$Month) <- c("01-Jan", "02-Feb",..., "12-Dec") and sort(levels(ctTEMP$Month).
  • To create a linear regression model w/ multiple categorical predictors use the code lm1 <- lm(TMIN ~ Year + Month + Name, data = ctTEMP).
  • Code to Try different reference levels is ctTEMP <- within(ctTEMP, Name <- relevel(Name, ref = "STORRS")).
  • Test normality of residuals and heteroskedasticity using the hist(lm1$residuals) function.
  • qqPlot(lm1$residuals) plots the values of the residuals.
  • plot(fitted(lm1), rstudent(lm1)) plots the fit of the residuals.

Module 19: ANOVA

  • ANOVA serves as a regression model with at least three levels of a categorical variable. A t-test can be used if there are only two.
  • The ANOVA assumptions are that the populations are from normal distributions, constant standard deviation/variance between groups, and all observations are independent.
  • ANOVA assumes a overall mean is modified by a "treatment effect".
  • It Quantifies the amount of variation observed in the dataset due to group identification.
  • To use the code CODE fit ANOVA model use code such as aov1 <- aov(cooperation ~ emotion).
  • Conducted is pairwise.t.test(cooperation, emotion, p.adjust = "none").
  • Turkey's Honestly Significant Difference Test is used using the code TukeyHSD(aov1).
  • ANOVA has a total sum of squares using the equation TOTAL sum squares = SSgroups + SSerrors.
  • ANOVA also has a null hypothesis where the mean in each groups are around the same.
  • ANOVA also has an alternative hypothesis means Do vary across groups.
  • ANOVA uses the code F=mean square group/ mean square be eror.

Module 20: Other Tests

  • Tests for equality of variances include Ho: σ₁=σ₂=...=σₙ and HA: one σᵢ different.
  • Assumes normality of group distributions and a p-value says if one SD is different.
  • Uses bartlett.text.
  • Levene's Test does NOT assume normality of variances but needs more robust data; test uses levene.Test.
  • Welch's ANOVA is for normal populations with unequal variances, and uses oneway.test(y~x).
  • Kruskal-Wallis Test assumes that there are NO DISTRIBUTIONAL ASSUMPTIONS and the HO states group medians are same while HA states at one group the median is different, test kruskal. test
  • Two-Way ANOVA is made of 2 categorical predictors + their interaction term with the same assumption of equal variances; uses, aov(y~ x + z + x*z)..
  • Uses interaction. plot(x, groups, response.
  • observation = overall mean + row factor effect & column factor effect+ interaction effect & residuals / errors.

Module 21: ANCOVA, GLMs

  • A generalized Linear Model is any kind of linear model ex regression, one-way Anova, tow-way Anova, 1 of 2 sample I tests.
  • Model can be expressed in the form Y = Bo + BiX. + B2X2 + ... + βnxn + €.
  • To calculate Type I Sum of Squares (Sequential) you calculate the Amant of model explained by a factor, by is affected by terms BEFORE IT.
  • You can find use the code to use other types of Sum of Squares such as to create ANOVA(..., type = "III").

Additional Concepts

  • To Prepare for exams review class material modules 16 to 22, review labs from 5 onwards, review labs and quizzes and complete a sample exam.
  • Exams will test: writing basic R code, knowing and understanding R functions, reading R code, interpreting R output, and applying substantial knowledge of key concepts.
  • Interpret continuous predictors (e.g., V241324, V241325, V241330x) such that a 1-point increase in the independent variable corresponds to a 𝛽 point change in the dependent variable (e.g., V241157, Trump feeling thermometer), holding all other variables constant.
  • For categorical predictors (e.g., V241227x, Party ID), coefficients represent the difference in outcome between each category and the baseline (reference) category, usually Independent.
  • The intercept represents the predicted value of the dependent variable when all continuous predictors are equal to 0, and all categorical predictors are at their reference (baseline) category.
  • Consider whether the intercept is meaningful in the context of the variables and if a value of 0 on a 1–7 scale has a real-world interpretation.

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team

Related Documents

More Like This

Use Quizgecko on...
Browser
Browser