Reading in the data set
PS3_DATA <- read.csv("ProblemSet3Data.csv")
Loading the needed library
library(psych)
library(ggplot2)
##
## Attaching package: 'ggplot2'
## The following objects are masked from 'package:psych':
##
## %+%, alpha
library(report)
PART I: Correlation and Regression
Pearson’s r Correlation between the average amount of eye movement while walking and the walkers’ speed
r<-corr.test(PS3_DATA$walk_eyex_mean,PS3_DATA$walk_eyex_speed)
print(r,short=F)
## Call:corr.test(x = PS3_DATA$walk_eyex_mean, y = PS3_DATA$walk_eyex_speed)
## Correlation matrix
## [1] 0.08
## Sample Size
## [1] 59
## These are the unadjusted probability values.
## The probability values adjusted for multiple tests are in the p.adj object.
## [1] 0.53
##
## Confidence intervals based upon normal theory. To get bootstrapped values, try cor.ci
## raw.lower raw.r raw.upper raw.p lower.adj upper.adj
## NA-NA -0.18 0.08 0.33 0.53 -0.18 0.33
Scatterplot
plot(PS3_DATA$walk_eyex_mean,PS3_DATA$walk_eyex_speed)
Regression to see if the walking speed predicts the average amount of eye movement
reg <- lm(walk_eyex_mean~walk_eyex_speed, data=PS3_DATA)
summary(reg)
##
## Call:
## lm(formula = walk_eyex_mean ~ walk_eyex_speed, data = PS3_DATA)
##
## Residuals:
## Min 1Q Median 3Q Max
## -7.649 -2.235 -0.202 2.479 7.651
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -3.0122 1.4475 -2.081 0.0419 *
## walk_eyex_speed 0.4549 0.7223 0.630 0.5314
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 3.412 on 57 degrees of freedom
## Multiple R-squared: 0.00691, Adjusted R-squared: -0.01051
## F-statistic: 0.3966 on 1 and 57 DF, p-value: 0.5314
report(reg)
## We fitted a linear model (estimated using OLS) to predict walk_eyex_mean with
## walk_eyex_speed (formula: walk_eyex_mean ~ walk_eyex_speed). The model explains
## a statistically not significant and very weak proportion of variance (R2 =
## 6.91e-03, F(1, 57) = 0.40, p = 0.531, adj. R2 = -0.01). The model's intercept,
## corresponding to walk_eyex_speed = 0, is at -3.01 (95% CI [-5.91, -0.11], t(57)
## = -2.08, p = 0.042). Within this model:
##
## - The effect of walk eyex speed is statistically non-significant and positive
## (beta = 0.45, 95% CI [-0.99, 1.90], t(57) = 0.63, p = 0.531; Std. beta = 0.08,
## 95% CI [-0.18, 0.35])
##
## Standardized parameters were obtained by fitting the model on a standardized
## version of the dataset. 95% Confidence Intervals (CIs) and p-values were
## computed using a Wald t-distribution approximation.
Confidence Intervals
confint(reg)
## 2.5 % 97.5 %
## (Intercept) -5.9106650 -0.1136448
## walk_eyex_speed -0.9915277 1.9012750
Plotting Regression
library(ggeffects)
gg<-ggpredict(reg,terms=c("walk_eyex_speed"))
plot(gg)+labs(x="walk_eyex_speed", y="walk_eyex_mean", title="")
PART II: t-Tests
One-sample t-test for the average amount of eye movement while searching Assuming the population average is 1.5
onesample <- t.test(PS3_DATA$search_eyex_mean,mu= 1.5)
report(onesample)
## Effect sizes were labelled following Cohen's (1988) recommendations.
##
## The One Sample t-test testing the difference between PS3_DATA$search_eyex_mean
## (mean = -4.32) and mu = 1.5 suggests that the effect is negative, statistically
## significant, and large (difference = -5.82, 95% CI [-4.97, -3.66], t(58) =
## -17.85, p < .001; Cohen's d = -2.32, 95% CI [-2.81, -1.83])
variance - homoscedasticity
var.test(PS3_DATA$search_eyex_mean, PS3_DATA$walk_eyex_mean)
##
## F test to compare two variances
##
## data: PS3_DATA$search_eyex_mean and PS3_DATA$walk_eyex_mean
## F = 0.54367, num df = 58, denom df = 58, p-value = 0.02184
## alternative hypothesis: true ratio of variances is not equal to 1
## 95 percent confidence interval:
## 0.3232836 0.9142826
## sample estimates:
## ratio of variances
## 0.5436658
Paired-samples t-test between the average amount of eye movement while searching and the average amount while walking
Pairedsamples <- t.test(PS3_DATA$search_eyex_mean,PS3_DATA$walk_eyex_mean, paired=T, var.equal=F)
report(Pairedsamples)
## Effect sizes were labelled following Cohen's (1988) recommendations.
##
## The Paired t-test testing the difference between PS3_DATA$search_eyex_mean and
## PS3_DATA$walk_eyex_mean (mean difference = -2.17) suggests that the effect is
## negative, statistically significant, and large (difference = -2.17, 95% CI
## [-2.87, -1.48], t(58) = -6.26, p < .001; Cohen's d = -0.81, 95% CI [-1.11,
## -0.52])
Independent-samples t-test
PS3_DATA$id <- as.factor(PS3_DATA$id)
levels(PS3_DATA$id) <- list('Female' = "1", 'Male' = "2")
FemaleEye <- (PS3_DATA$search_eyex_mean[PS3_DATA$id == "Female"])
describe(FemaleEye)
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 29 -4.21 2.54 -3.65 -4.05 2.12 -10.72 0.14 10.85 -0.72 -0.23 0.47
MaleEye <- (PS3_DATA$search_eyex_mean[PS3_DATA$id == "Male"])
describe(MaleEye) #Computing M and SD of females and males negative life events
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 30 -4.42 2.5 -4.17 -4.47 2.82 -9.02 2.16 11.18 0.27 -0.27 0.46
Independent Samples t-test comparing males and females eye movement while searching
var.test(FemaleEye, MaleEye)
##
## F test to compare two variances
##
## data: FemaleEye and MaleEye
## F = 1.0298, num df = 28, denom df = 29, p-value = 0.9363
## alternative hypothesis: true ratio of variances is not equal to 1
## 95 percent confidence interval:
## 0.4879986 2.1839055
## sample estimates:
## ratio of variances
## 1.02979
IndSamt <- t.test(FemaleEye, MaleEye, var.equal=T)
report(IndSamt)
## Warning: Missing values detected. NAs dropped.
## Effect sizes were labelled following Cohen's (1988) recommendations.
##
## The Two Sample t-test testing the difference between FemaleEye and MaleEye
## (mean of x = -4.21, mean of y = -4.42) suggests that the effect is positive,
## statistically not significant, and very small (difference = 0.21, 95% CI
## [-1.10, 1.53], t(57) = 0.33, p = 0.745; Cohen's d = 0.08, 95% CI [-0.43, 0.60])
Descriptives
describe(PS3_DATA$search_eyex_mean)
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 59 -4.32 2.5 -3.9 -4.25 2.53 -10.72 2.16 12.88 -0.24 -0.24 0.33
describe(PS3_DATA$walk_eyex_mean)
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 59 -2.14 3.39 -2.26 -2.2 3.63 -9.4 5.72 15.12 0.1 -0.52 0.44
describe(FemaleEye)
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 29 -4.21 2.54 -3.65 -4.05 2.12 -10.72 0.14 10.85 -0.72 -0.23 0.47
describe(MaleEye)
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 30 -4.42 2.5 -4.17 -4.47 2.82 -9.02 2.16 11.18 0.27 -0.27 0.46
power analysis for my data that is analyzing the correlation between infants’ body postitons and the amount of language they hear from adults
library(pwr)
pwr.r.test(r = .3, sig.level = .05, power = .8)
##
## approximate correlation power calculation (arctangh transformation)
##
## n = 84.07364
## r = 0.3
## sig.level = 0.05
## power = 0.8
## alternative = two.sided