• Home
  • University of Queensland
  • Analysis Of Scientific Data
  • Statistical Analysis and Hypothesis Testing in R

Statistical Analysis and Hypothesis Testing in R

Standard Error for population means : In t = qt(0.975, df= ) on R studio Degrees of freedom: n-1 Degrees of freedom for two groups: (n1-1)+(n2-1) 95% confidence interval margin of error: t * standard error(x) Standard Error for Sample Means = n1 (01)2 + (02)2 n2 T-statistic: m-u standard error (m = sample mean, mew= theoretical mean (null hypothesis -> 0 difference in the means;no change) P-value for t-statistic. Rstudio=> 2*(1-pt([enter t statistic], [enter degrees of freedom]) *DONT DO 1- if the critical value is already negative Mean of transformed Variables: aggregate(Y~X,data,mean) Null hypothesis: - If it's asking for the null hypothesis between the mean values of two groups: HO - means between the two groups equal each other. H1- the means between the two groups don't equal each other - If it's asking for the null hypothesis between the group mean before and after treatment -> HO = there's no change in mean, H1 = there's a positive change in mean Statistical tests: Rank sum test: Can assess the difference in effect (and significance of the different) between two treatment groups. Linear Regression Models: Normal probability plots can't be used to assess linearity. Instead, linearity can only be assessed through scatter plots. Standard error for a new category based off an old mean: this requires you to assume independence. Std = new mean x old(var(x)) Standard error of a proportion = p(1-p) n Standard error for the difference in two proportions: p1(1-p) n1 + n2 p2(1-p2) P-value for the significance in difference between two proportions: 2*(1-pnorm(z)) where z (proportion1 - proportion2) - 0 = standard error for the difference between the two proportions T statistic that subjects in a particular group have a higher/lower mean -> t.test(Y~X,data=data,alternative='greater/less') Use greater if the No is bigger than Yes Use less is the Yes is bigger than No Relationships between variables (welch t.test i think) - t.test(Y~X, data=data) gives P value and the degrees of freedom - t.test(migraine$Days0) Reading a csv file: data = read.csv('[insertname].csv') Summary statistics: summary(data) · Gives min, Q1, median, mean, Q3, max for all categories at once · Otherwise: ? Basic mean: mean(data$variable) o Standard Deviation: sd(data$variable) o Median: median(data$variable) o IQR: IQR(data$variable) ? Table: table(data$variable) Finding shape of distribution: bwplot(~variable, data) and/or histogram(~variable, data) · Observe skewness Mean Median Mode Median Median Mode-1 1-Mean Mean-1 - Mode Positive Skew Symmetrical Distribution Negative Skew Finding mean of the group within a variable: aggregate(Y ~ X, data, mean) Finding out the number of participants in a subgroup: table(data$variable) Finding out the proportion of variable 1 participants in the variable 2 group: prop.table(table(data$variable1,data$variable2), 1) Estimated Difference in Proportion: prop.test(table(data$X,data$Y)) and calculate the difference between prop 1 and prop 2 GENERAL RELATIONSHIPS BETWEEN TWO VARIABLES - Correlation: cor(data$X,data$Y - slope of the least-squares summary(Im(Y ~ X, data=data)) -> you're looking for the co-efficient of the X value - Predicting an x value: predict(lm(Y ~ X, data=data), newdata=data.frame((X= )) - 95% prediction model: predict(lm(Y~ X, data=data),newdata=data.frame(X= ), interval="predict") Multiple Regression Analysis