jackmwolf / pcsstools

Tools for regression using pre-computed summary statistics

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

model_combo() does not label coefficients correctly

jackmwolf opened this issue · comments

When modeling a function with only one predictor, calculate_lm() does not label "(Intercept)" in output coefficients.
The following example shows output from model_combo(), which calls calculate_lm().

library(grass)
ex_data <- cont_data

means <- colMeans(ex_data)
covs <- cov(ex_data)
n <- nrow(ex_data)

phi <- c(1, 1)

model_combo(y1 + y2 ~ x, n = n, phi = phi, means = means, covs = covs)
#> Model approximated using Pre-Computed Summary Statistics.
#> 
#> Call:
#> model_combo(formula = y1 + y2 ~ x, phi = phi, n = n, means = means, 
#>     covs = covs)
#> 
#> Coefficients:
#>   Estimate Std. Error t value Pr(>|t|)    
#>   -0.50990    0.03349  -15.22   <2e-16 ***
#> x -0.89016    0.03287  -27.08   <2e-16 ***
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> 
#> Residual standard error: 1.059 on 998 degrees of freedom
#> Multiple R-squared:  0.4236, Adjusted R-squared:  0.423 
#> F-statistic: 733.3 on 1 and 998 DF,  p-value: < 2.2e-16

summary(lm(y1 + y2 ~ x, data = cont_data))
#> 
#> Call:
#> lm(formula = y1 + y2 ~ x, data = cont_data)
#> 
#> Residuals:
#>     Min      1Q  Median      3Q     Max 
#> -3.2948 -0.7576 -0.0582  0.7384  3.4200 
#> 
#> Coefficients:
#>             Estimate Std. Error t value Pr(>|t|)    
#> (Intercept) -0.50990    0.03349  -15.22   <2e-16 ***
#> x           -0.89016    0.03287  -27.08   <2e-16 ***
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> 
#> Residual standard error: 1.059 on 998 degrees of freedom
#> Multiple R-squared:  0.4236, Adjusted R-squared:  0.423 
#> F-statistic: 733.3 on 1 and 998 DF,  p-value: < 2.2e-16

There is a similar but different issue using either model_or() or model_and(). Models with only one predictor will label said predictor as NA.

library(grass)

ex_data <- bin_data

means <- colMeans(ex_data)
covs <- cov(ex_data)
n <- nrow(ex_data)
predictors <- list(
 g = new_predictor_snp(maf = mean(ex_data$g) / 2),
 x = new_predictor_normal(mean = mean(ex_data$x), sd = sd(ex_data$x))
)

model_and(
 y1 & y2 ~ g,
 means = means, covs = covs, n = n, predictors = predictors
)
#> Model approximated using Pre-Computed Summary Statistics.
#> 
#> Call:
#> model_and(formula = y1 & y2 ~ g, n = n, means = means, covs = covs, 
#>     predictors = predictors)
#> 
#> Coefficients:
#>             Estimate Std. Error t value Pr(>|t|)    
#> (Intercept)  0.19601    0.01382  14.179  < 2e-16 ***
#> NA          -0.11797    0.01616  -7.301 5.82e-13 ***
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> 
#> Residual standard error: 0.3269 on 998 degrees of freedom
#> Multiple R-squared:  0.05071,    Adjusted R-squared:  0.04976 
#> F-statistic: 53.31 on 1 and 998 DF,  p-value: 5.819e-13