Package 'Keng'

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

Help Index


Compare lm.fit using PRE and R square.

Description

Compare lm.fit using PRE and R square.

Usage

compare_lm(
  fitC = NULL,
  fitA = NULL,
  n = NULL,
  PC = NULL,
  PA = NULL,
  SSEC = NULL,
  SSEA = NULL
)

Arguments

fitC

The result of lm() of the Compact model (Model C).

fitA

The result of lm() of the Augmented model (Model A).

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.

Details

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.

Value

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.

References

Judd, C. M., McClelland, G. H., & Ryan, C. S. (2017). Data analysis: A model comparison approach to regression, ANOVA, and beyond. Routledge.

Examples

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.

Description

Cut-off values of r given the sample size n.

Usage

cut_r(n)

Arguments

n

Sample size of the r.

Details

Given n and p, t and then r could be determined. The formula used could be found in test_r()'s documentation.

Value

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.

Examples

cut_r(193)

Test r using the t-test given r and n.

Description

Test r using the t-test given r and n.

Usage

test_r(r, n)

Arguments

r

Pearson correlation.

n

Sample size of r.

Details

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)).

Value

A data.frame including r, se of r, t, and p.

Examples

test_r(0.2, 193)