Title: | Knock Errors off Nice Guesses |
---|---|
Description: | Miscellaneous functions and data used in Qingyao's psychological research and teaching. |
Authors: | Qingyao Zhang [aut, cre] |
Maintainer: | Qingyao Zhang <[email protected]> |
License: | CC BY 4.0 |
Version: | 2024.10.20 |
Built: | 2024-10-20 14:14:29 UTC |
Source: | https://github.com/qyaozh/keng |
Compare lm.fit using PRE and R square.
compare_lm( fitC = NULL, fitA = NULL, n = NULL, PC = NULL, PA = NULL, SSEC = NULL, SSEA = NULL )
compare_lm( fitC = NULL, fitA = NULL, n = NULL, PC = NULL, PA = NULL, SSEC = NULL, SSEA = NULL )
fitC |
The result of |
fitA |
The result of |
n |
Sample size of the Model C or Model A. Model C and Model A must use the same sample, and hence have the same sample size. |
PC |
The number of parameters in Model C. |
PA |
The number of parameters in Model A. PA must be larger than PC. |
SSEC |
The Sum of Squared Errors (SSE) of Model C. |
SSEA |
The Sum of Squared Errors of Model A. |
compare_lm()
compare Model A with Model C using PRE (Proportional Reduction in Error) and R square. There are two ways of using compare_lm()
. The first is giving compare_lm()
fitC and fitA. The second is giving n, PC, PA, SSEC, and SSEA. The first way is more convenient, and it minimizes precision loss by omitting copying and pasting SSEC and SSEA. If fitC and fitA are not inferior to the intercept-only model, R-Square and Adjusted R-Square are also computed. Note that the F-tests for PRE and R-square change are equivalent. Please refer to Judd et al. (2017) for more details about PRE.
A data.frame including SSE, PRE, the F-test of PRE (F, df1, df2, p), and PRE_adjusted. If fitC and fitA are not inferior to the intercept-only model, R-Square and Adjusted R-Square will also be computed.
Judd, C. M., McClelland, G. H., & Ryan, C. S. (2017). Data analysis: A model comparison approach to regression, ANOVA, and beyond. Routledge.
x1 <- rnorm(193) x2 <- rnorm(193) y <- 0.3 + 0.2*x1 + 0.1*x2 + rnorm(193) dat <- data.frame(y, x1, x2) fit1 <- lm(I(y - 1) ~ 0, dat) fit2 <- lm(y ~ 1, dat) fit3 <- lm(y ~ x1, dat) fit4 <- lm(y ~ x1 + x2, dat) compare_lm(fit1, fit2) compare_lm(fit2, fit3) compare_lm(fit3, fit4) compare_lm(fit2, fit4)
x1 <- rnorm(193) x2 <- rnorm(193) y <- 0.3 + 0.2*x1 + 0.1*x2 + rnorm(193) dat <- data.frame(y, x1, x2) fit1 <- lm(I(y - 1) ~ 0, dat) fit2 <- lm(y ~ 1, dat) fit3 <- lm(y ~ x1, dat) fit4 <- lm(y ~ x1 + x2, dat) compare_lm(fit1, fit2) compare_lm(fit2, fit3) compare_lm(fit3, fit4) compare_lm(fit2, fit4)
Cut-off values of r given the sample size n.
cut_r(n)
cut_r(n)
n |
Sample size of the r. |
Given n and p, t and then r could be determined. The formula used could be found in test_r()
's documentation.
A data.frame including the cut-off values of r at the significance levels of p = 0.1, 0.05, 0.01, 0.001. r with the absolute value larger than the cut-off value is significant at the corresponding significance level.
cut_r(193)
cut_r(193)
Test r using the t-test given r and n.
test_r(r, n)
test_r(r, n)
r |
Pearson correlation. |
n |
Sample size of r. |
To test the significance of the r using one-sample t-test, the SE of the r is determined by the following formula: SE = sqrt((1 - r^2)/(n - 2))
.
A data.frame including r, se of r, t, and p.
test_r(0.2, 193)
test_r(0.2, 193)