troubleshooting and fixing

This commit is contained in:
agdamsbo 2019-11-08 12:22:49 +01:00
parent 7902654ed7
commit 8326ed2cc0
50 changed files with 88 additions and 262 deletions

BIN
.DS_Store vendored

Binary file not shown.

View File

@ -2,16 +2,12 @@ Package: daDoctoR
Type: Package Type: Package
Title: FUNCTIONS FOR HEALTH RESEARCH Title: FUNCTIONS FOR HEALTH RESEARCH
Version: 0.1.0.9023 Version: 0.1.0.9023
Author@R: c(person("Andreas", "Gammelgaard Damsbo", email = "agdamsbo@pm.me", role = c("cre", "aut"))) Author: c(person("Andreas", "Gammelgaard Damsbo", email = "agdamsbo@pm.me", role = c("cre", "aut")))
Maintainer: Andreas Gammelgaard Damsbo <agdamsbo@pm.me> Maintainer: Andreas Gammelgaard Damsbo <agdamsbo@pm.me>
Description: I am a Danish medical doctor involved in neuropsychiatric research. Description: I am a Danish medical doctor involved in neuropsychiatric research.
Here I have collected functions I use for my data analysis. You are very Here I have collected functions I use for my data analysis. You are very
welcome to get inspired or to use my work. welcome to get inspired or to use my work.
Imports: broom, Imports: broom, dplyr, epiR, ggplot2, MASS
dplyr,
epiR,
ggplot2,
MASS
Suggest: shiny Suggest: shiny
License: GPL (>= 2) License: GPL (>= 2)
Encoding: UTF-8 Encoding: UTF-8

View File

@ -7,9 +7,6 @@
#' @param labels labels for all selected columns #' @param labels labels for all selected columns
#' @keywords factor #' @keywords factor
#' @export #' @export
#' @examples
#' col_fact()
col_fact<-function(string,data,levels=NULL,labels=NULL){ col_fact<-function(string,data,levels=NULL,labels=NULL){
## Defining factors for columns containing string (can be vector of multiple strings), based on dplyr. ## Defining factors for columns containing string (can be vector of multiple strings), based on dplyr.

View File

@ -5,8 +5,6 @@
#' @param data Dataframe #' @param data Dataframe
#' @keywords numeric #' @keywords numeric
#' @export #' @export
#' @examples
#' col_num()
col_num<-function(string,data){ col_num<-function(string,data){
## Defining factors for columns containing string (can be vector of multiple strings), based on dplyr ## Defining factors for columns containing string (can be vector of multiple strings), based on dplyr

View File

@ -3,12 +3,9 @@
#' Should be combined with "rep_olr()". The confint() function is rather slow, causing the whole function to hang when including many predictors and calculating the ORs with CI. #' Should be combined with "rep_olr()". The confint() function is rather slow, causing the whole function to hang when including many predictors and calculating the ORs with CI.
#' @param meas primary outcome (factor with >2 levels). #' @param meas primary outcome (factor with >2 levels).
#' @param vars variables in model. Input as c() of columnnames, use dput(). #' @param vars variables in model. Input as c() of columnnames, use dput().
#' @param dta data frame to pull variables from. #' @param data data frame to pull variables from.
#' @keywords olr #' @keywords olr
#' @export #' @export
#' @examples
#' comb_olr()
comb_olr<-function(meas,vars,data){ comb_olr<-function(meas,vars,data){
require(MASS) require(MASS)

View File

@ -4,12 +4,10 @@
#' @param x data as as dd/mm/yyyy. #' @param x data as as dd/mm/yyyy.
#' @keywords date #' @keywords date
#' @export #' @export
#' @examples
#' date_convert()
date_convert<-function(x) date_convert<-function(x)
## Input format as dd/mm/yyyy, output is standard yyyy-mm-dd ## Input format as dd/mm/yyyy, output is standard yyyy-mm-dd
{ {
result<-as.Date(x, format="%d/%m/%Y") result<-as.Date(x, format="%d/%m/%Y")
print(result) print(result)
} }

View File

@ -5,53 +5,51 @@
#' @param y Allele 2. #' @param y Allele 2.
#' @keywords hardy-weinberg-equllibrium #' @keywords hardy-weinberg-equllibrium
#' @export #' @export
#' @examples
#' hwe_allele()
hwe_allele<-function(x,y) hwe_allele<-function(x,y)
{ {
## Witten by Andreas Gammelgaard Damsbo, agdamsbo@pm.me, based on a non-working ## Witten by Andreas Gammelgaard Damsbo, agdamsbo@pm.me, based on a non-working
## applet at from http://www.husdyr.kvl.dk/htm/kc/popgen/genetik/applets/kitest.htm ## applet at http://www.husdyr.kvl.dk/htm/kc/popgen/genetik/applets/kitest.htm
all<-pmax(length(levels(factor(x))),length(levels(factor(y)))) all<-pmax(length(levels(factor(x))),length(levels(factor(y))))
if(all==2){ if(all==2){
df=1 df=1
## Biallellic system, df=1 ## Biallellic system, df=1
al1<-factor(x,labels=c("p","q")) al1<-factor(x,labels=c("p","q"))
al2<-factor(y,labels=c("p","q")) al2<-factor(y,labels=c("p","q"))
snp<-paste(al1,al2,sep = "_") snp<-paste(al1,al2,sep = "_")
snp[snp=="q_p"]<-"p_q" snp[snp=="q_p"]<-"p_q"
snp_f<-factor(snp,levels=c("p_p", "p_q", "q_q")) snp_f<-factor(snp,levels=c("p_p", "p_q", "q_q"))
a<-length(snp)*2 a<-length(snp)*2
b<-length(snp) b<-length(snp)
p<-(length(al1[al1=="p"])+length(al2[al2=="p"]))/a p<-(length(al1[al1=="p"])+length(al2[al2=="p"]))/a
q<-(length(al1[al1=="q"])+length(al2[al2=="q"]))/a q<-(length(al1[al1=="q"])+length(al2[al2=="q"]))/a
al_dist<-round(rbind(cbind(p*a,q*a),cbind(p*100,q*100)),1) al_dist<-round(rbind(cbind(p*a,q*a),cbind(p*100,q*100)),1)
al_names<-levels(factor(x)) al_names<-levels(factor(x))
p_p<-round(p^2*b,3) p_p<-round(p^2*b,3)
p_q<-round(2*p*q*b,3) p_q<-round(2*p*q*b,3)
q_q<-round(q^2*b,3) q_q<-round(q^2*b,3)
hwe<-data.frame(obs=summary(snp_f),exp=rbind(p_p, p_q, q_q)) hwe<-data.frame(obs=summary(snp_f),exp=rbind(p_p, p_q, q_q))
hwe$dev<-hwe$obs-hwe$exp hwe$dev<-hwe$obs-hwe$exp
hwe$chi<-hwe$dev^2/hwe$exp hwe$chi<-hwe$dev^2/hwe$exp
snp_obs<-round(rbind(summary(snp_f),summary(snp_f)/length(snp_f)*100),1) snp_obs<-round(rbind(summary(snp_f),summary(snp_f)/length(snp_f)*100),1)
snp_exp<-round(rbind(hwe$exp,hwe$exp/b*100),1) snp_exp<-round(rbind(hwe$exp,hwe$exp/b*100),1)
gen_names<-c( gen_names<-c(
paste(levels(factor(x))[1],levels(factor(x))[1],sep="_"), paste(levels(factor(x))[1],levels(factor(x))[1],sep="_"),
paste(levels(factor(x))[1],levels(factor(x))[2],sep="_"), paste(levels(factor(x))[1],levels(factor(x))[2],sep="_"),
paste(levels(factor(x))[2],levels(factor(x))[2],sep="_")) paste(levels(factor(x))[2],levels(factor(x))[2],sep="_"))
chi<-sum(hwe$chi,na.rm = TRUE) chi<-sum(hwe$chi,na.rm = TRUE)
p_v<-pchisq(chi, df=df, lower.tail=FALSE) p_v<-pchisq(chi, df=df, lower.tail=FALSE)
} }
@ -60,39 +58,39 @@ hwe_allele<-function(x,y)
## Triallellic system, df=3 ## Triallellic system, df=3
al1<-factor(x,labels=c("p","q","r")) al1<-factor(x,labels=c("p","q","r"))
al2<-factor(y,labels=c("p","q","r")) al2<-factor(y,labels=c("p","q","r"))
snp<-paste(al1,al2,sep = "_") snp<-paste(al1,al2,sep = "_")
snp[snp=="r_p"]<-"p_r" snp[snp=="r_p"]<-"p_r"
snp[snp=="r_q"]<-"q_r" snp[snp=="r_q"]<-"q_r"
snp[snp=="q_p"]<-"p_q" snp[snp=="q_p"]<-"p_q"
snp_f<-factor(snp,levels=c("p_p", "p_q", "q_q","p_r","q_r", "r_r")) snp_f<-factor(snp,levels=c("p_p", "p_q", "q_q","p_r","q_r", "r_r"))
a<-length(snp)*2 a<-length(snp)*2
b<-length(snp) b<-length(snp)
p<-(length(al1[al1=="p"])+length(al2[al2=="p"]))/a p<-(length(al1[al1=="p"])+length(al2[al2=="p"]))/a
q<-(length(al1[al1=="q"])+length(al2[al2=="q"]))/a q<-(length(al1[al1=="q"])+length(al2[al2=="q"]))/a
r<-(length(al1[al1=="r"])+length(al2[al2=="r"]))/a r<-(length(al1[al1=="r"])+length(al2[al2=="r"]))/a
al_dist<-round(rbind(cbind(p*a,q*a,r*a),cbind(p*100,q*100,r*100)),1) al_dist<-round(rbind(cbind(p*a,q*a,r*a),cbind(p*100,q*100,r*100)),1)
al_names<-levels(factor(x)) al_names<-levels(factor(x))
p_p<-round(p^2*b,3) p_p<-round(p^2*b,3)
p_q<-round(2*p*q*b,3) p_q<-round(2*p*q*b,3)
q_q<-round(q^2*b,3) q_q<-round(q^2*b,3)
p_r<-round(2*r*p*b,3) p_r<-round(2*r*p*b,3)
q_r<-round(2*q*r*b,3) q_r<-round(2*q*r*b,3)
r_r<-round(r^2*b,3) r_r<-round(r^2*b,3)
hwe<-data.frame(obs=summary(snp_f),exp=rbind(p_p, p_q, q_q, p_r, q_r, r_r)) hwe<-data.frame(obs=summary(snp_f),exp=rbind(p_p, p_q, q_q, p_r, q_r, r_r))
hwe$dev<-hwe$obs-hwe$exp hwe$dev<-hwe$obs-hwe$exp
hwe$chi<-hwe$dev^2/hwe$exp hwe$chi<-hwe$dev^2/hwe$exp
snp_obs<-round(rbind(summary(snp_f),summary(snp_f)/length(snp_f)*100),1) snp_obs<-round(rbind(summary(snp_f),summary(snp_f)/length(snp_f)*100),1)
snp_exp<-round(rbind(hwe$exp,hwe$exp/b*100),1) snp_exp<-round(rbind(hwe$exp,hwe$exp/b*100),1)
gen_names<-c( gen_names<-c(
paste(levels(factor(x))[1],levels(factor(x))[1],sep="_"), paste(levels(factor(x))[1],levels(factor(x))[1],sep="_"),
paste(levels(factor(x))[1],levels(factor(x))[2],sep="_"), paste(levels(factor(x))[1],levels(factor(x))[2],sep="_"),
@ -100,30 +98,30 @@ hwe_allele<-function(x,y)
paste(levels(factor(x))[1],levels(factor(x))[3],sep="_"), paste(levels(factor(x))[1],levels(factor(x))[3],sep="_"),
paste(levels(factor(x))[2],levels(factor(x))[3],sep="_"), paste(levels(factor(x))[2],levels(factor(x))[3],sep="_"),
paste(levels(factor(x))[3],levels(factor(x))[3],sep="_")) paste(levels(factor(x))[3],levels(factor(x))[3],sep="_"))
chi<-sum(hwe$chi,na.rm = TRUE) chi<-sum(hwe$chi,na.rm = TRUE)
p_v<-pchisq(chi, df=df, lower.tail=FALSE) p_v<-pchisq(chi, df=df, lower.tail=FALSE)
} }
else if (!any(all==c(2,3))){stop("This formula only works for bi- or triallellic systems")} else if (!any(all==c(2,3))){stop("This formula only works for bi- or triallellic systems")}
else {stop("There was an unknown error")} else {stop("There was an unknown error")}
colnames(al_dist)<-al_names colnames(al_dist)<-al_names
colnames(snp_obs)<-gen_names colnames(snp_obs)<-gen_names
colnames(snp_exp)<-gen_names colnames(snp_exp)<-gen_names
rn<-c("N","%") rn<-c("N","%")
rownames(al_dist)<-rn rownames(al_dist)<-rn
rownames(snp_obs)<-rn rownames(snp_obs)<-rn
rownames(snp_exp)<-rn rownames(snp_exp)<-rn
int<-ifelse(p_v<=0.05,"The null-hypothesis of difference from the HWE can be confirmed","The null-hypothesis of difference from the HWE can be rejected") int<-ifelse(p_v<=0.05,"The null-hypothesis of difference from the HWE can be confirmed","The null-hypothesis of difference from the HWE can be rejected")
t1<-"Chi-square test for Hardy-Weinberg equillibrium for a bi- or triallellic system. Read more: http://www.husdyr.kvl.dk/htm/kc/popgen/genetics/2/2.htm" t1<-"Chi-square test for Hardy-Weinberg equillibrium for a bi- or triallellic system. Read more: http://www.husdyr.kvl.dk/htm/kc/popgen/genetics/2/2.htm"
list<-list(info=t1,n.total=b,allele.dist=al_dist,observed.dist=snp_obs,expected.dist=snp_exp,chi.value=chi,p.value=p_v,df=df,interpretation=int) list<-list(info=t1,n.total=b,allele.dist=al_dist,observed.dist=snp_obs,expected.dist=snp_exp,chi.value=chi,p.value=p_v,df=df,interpretation=int)
return(list) return(list)
} }

View File

@ -3,6 +3,7 @@
#' App to easily calculate and visualize the HWE. #' App to easily calculate and visualize the HWE.
#' #'
#' @export #' @export
hwe_app <- function() { hwe_app <- function() {
appDir <- system.file("shiny-examples", "hwe_calc", package = "daDoctoR") appDir <- system.file("shiny-examples", "hwe_calc", package = "daDoctoR")
if (appDir == "") { if (appDir == "") {

View File

@ -4,100 +4,98 @@
#' @param mm First count of genotype. #' @param mm First count of genotype.
#' @keywords hardy-weinberg-equllibrium #' @keywords hardy-weinberg-equllibrium
#' @export #' @export
#' @examples
#' hwe_geno()
hwe_geno<-function(mm,mn,nn,mo,no,oo,alleles=2) hwe_geno<-function(mm,mn,nn,mo,no,oo,alleles=2)
{ {
## x is the number of common homozygote, y the heterozygote and z the rare homozygote. ## x is the number of common homozygote, y the heterozygote and z the rare homozygote.
if (alleles==2){ if (alleles==2){
## Biallelic has three degrees of freedom ## Biallelic has three degrees of freedom
df=1 df=1
a<-sum(mm,mn,nn)*2 a<-sum(mm,mn,nn)*2
b<-sum(mm,mn,nn) b<-sum(mm,mn,nn)
p<-(2*mm+mn)/a p<-(2*mm+mn)/a
q<-(2*nn+mn)/a q<-(2*nn+mn)/a
al_dist<-round(rbind(cbind(p*a,q*a),cbind(p*100,q*100)),1) al_dist<-round(rbind(cbind(p*a,q*a),cbind(p*100,q*100)),1)
al_names<-c("m","n") al_names<-c("m","n")
p_p<-round(p^2*b,3) p_p<-round(p^2*b,3)
p_q<-round(2*p*q*b,3) p_q<-round(2*p*q*b,3)
q_q<-round(q^2*b,3) q_q<-round(q^2*b,3)
obs=rbind(mm,mn,nn) obs=rbind(mm,mn,nn)
exp=rbind(p_p, p_q, q_q) exp=rbind(p_p, p_q, q_q)
hwe<-data.frame(obs,exp) hwe<-data.frame(obs,exp)
hwe$dev<-hwe$obs-hwe$exp hwe$dev<-hwe$obs-hwe$exp
hwe$chi<-hwe$dev^2/hwe$exp hwe$chi<-hwe$dev^2/hwe$exp
snp_obs<-round(rbind(hwe$obs,hwe$obs/sum(hwe$obs)*100),1) snp_obs<-round(rbind(hwe$obs,hwe$obs/sum(hwe$obs)*100),1)
snp_exp<-round(rbind(hwe$exp,hwe$exp/b*100),1) snp_exp<-round(rbind(hwe$exp,hwe$exp/b*100),1)
gen_names<-c("mm","mn","nn") gen_names<-c("mm","mn","nn")
chi<-sum(hwe$chi,na.rm = TRUE) chi<-sum(hwe$chi,na.rm = TRUE)
p_v<-pchisq(chi, df=df, lower.tail=FALSE) p_v<-pchisq(chi, df=df, lower.tail=FALSE)
} }
if(alleles==3){ if(alleles==3){
## Triallelic has three degrees of freedom ## Triallelic has three degrees of freedom
df=3 df=3
a<-sum(mm,mn,nn,mo,no,oo)*2 a<-sum(mm,mn,nn,mo,no,oo)*2
b<-sum(mm,mn,nn,mo,no,oo) b<-sum(mm,mn,nn,mo,no,oo)
p<-(2*mm+mn+mo)/a p<-(2*mm+mn+mo)/a
q<-(2*nn+mn+no)/a q<-(2*nn+mn+no)/a
r<-(2*oo+no+mo)/a r<-(2*oo+no+mo)/a
al_dist<-round(rbind(cbind(p*a,q*a,r*a),cbind(p*100,q*100,r*100)),1) al_dist<-round(rbind(cbind(p*a,q*a,r*a),cbind(p*100,q*100,r*100)),1)
al_names<-c("m","n","o") al_names<-c("m","n","o")
p_p<-round(p^2*b,3) p_p<-round(p^2*b,3)
p_q<-round(2*p*q*b,3) p_q<-round(2*p*q*b,3)
q_q<-round(q^2*b,3) q_q<-round(q^2*b,3)
p_r<-round(2*r*p*b,3) p_r<-round(2*r*p*b,3)
q_r<-round(2*q*r*b,3) q_r<-round(2*q*r*b,3)
r_r<-round(r^2*b,3) r_r<-round(r^2*b,3)
obs=rbind(mm,mn,nn,mo,no,oo) obs=rbind(mm,mn,nn,mo,no,oo)
exp=rbind(p_p, p_q, q_q, p_r, q_r, r_r) exp=rbind(p_p, p_q, q_q, p_r, q_r, r_r)
hwe<-data.frame(obs,exp) hwe<-data.frame(obs,exp)
hwe$dev<-hwe$obs-hwe$exp hwe$dev<-hwe$obs-hwe$exp
hwe$chi<-hwe$dev^2/hwe$exp hwe$chi<-hwe$dev^2/hwe$exp
snp_obs<-round(rbind(hwe$obs,hwe$obs/sum(hwe$obs)*100),1) snp_obs<-round(rbind(hwe$obs,hwe$obs/sum(hwe$obs)*100),1)
snp_exp<-round(rbind(hwe$exp,hwe$exp/b*100),1) snp_exp<-round(rbind(hwe$exp,hwe$exp/b*100),1)
gen_names<-c("mm","mn","nn", "mo", "no", "oo") gen_names<-c("mm","mn","nn", "mo", "no", "oo")
chi<-sum(hwe$chi,na.rm = TRUE) chi<-sum(hwe$chi,na.rm = TRUE)
p_v<-pchisq(chi, df=df, lower.tail=FALSE) p_v<-pchisq(chi, df=df, lower.tail=FALSE)
} }
colnames(al_dist)<-al_names colnames(al_dist)<-al_names
colnames(snp_obs)<-gen_names colnames(snp_obs)<-gen_names
colnames(snp_exp)<-gen_names colnames(snp_exp)<-gen_names
rownames(al_dist)<-c("N","%") rownames(al_dist)<-c("N","%")
rownames(snp_obs)<-c("N","%") rownames(snp_obs)<-c("N","%")
rownames(snp_exp)<-c("N","%") rownames(snp_exp)<-c("N","%")
int<-ifelse(p_v<=0.05,"The null-hypothesis of difference from the HWE can be confirmed","The null-hypothesis of difference from the HWE can be rejected") int<-ifelse(p_v<=0.05,"The null-hypothesis of difference from the HWE can be confirmed","The null-hypothesis of difference from the HWE can be rejected")
t1<-"Chi-square test for Hardy-Weinberg equillibrium for a bi- or triallellic system. Theory: http://www.husdyr.kvl.dk/htm/kc/popgen/genetics/2/2.htm" t1<-"Chi-square test for Hardy-Weinberg equillibrium for a bi- or triallellic system. Theory: http://www.husdyr.kvl.dk/htm/kc/popgen/genetics/2/2.htm"
list<-list(info=t1,n.total=b,allele.dist=al_dist,observed.dist=snp_obs,expected.dist=snp_exp,chi.value=chi,p.value=p_v,df=df,interpretation=int) list<-list(info=t1,n.total=b,allele.dist=al_dist,observed.dist=snp_obs,expected.dist=snp_exp,chi.value=chi,p.value=p_v,df=df,interpretation=int)
return(list) return(list)
} }

View File

@ -6,8 +6,6 @@
#' @param f factor for grouping. #' @param f factor for grouping.
#' @keywords hardy-weinberg-equllibrium #' @keywords hardy-weinberg-equllibrium
#' @export #' @export
#' @examples
#' hwe_sum()
hwe_sum<-function (a1, a2, f) { hwe_sum<-function (a1, a2, f) {
require(daDoctoR) require(daDoctoR)

View File

@ -11,8 +11,6 @@
#' @param input can be either "model", which is a olr model (polr()), or "df", which is a dataframe whith three columns for OR, lower CI and upper CI- #' @param input can be either "model", which is a olr model (polr()), or "df", which is a dataframe whith three columns for OR, lower CI and upper CI-
#' @keywords forestplot #' @keywords forestplot
#' @export #' @export
#' @examples
#' plot_ord_odds()
plot_ord_odds<-function(x, title = NULL,dec=3,lbls=NULL,hori="OR (95 % CI)",vert="Variables",short=FALSE,input="model"){ plot_ord_odds<-function(x, title = NULL,dec=3,lbls=NULL,hori="OR (95 % CI)",vert="Variables",short=FALSE,input="model"){

View File

@ -9,8 +9,6 @@
#' @param logistic flag for logistic binomial regression or not (linear is then selected). #' @param logistic flag for logistic binomial regression or not (linear is then selected).
#' @keywords logistic regression #' @keywords logistic regression
#' @export #' @export
#' @examples
#' rep_biv()
rep_biv<-function(y,v1,string,data,method="pval",logistic=FALSE,ci=FALSE,cut=0.1,v2=NULL,v3=NULL){ rep_biv<-function(y,v1,string,data,method="pval",logistic=FALSE,ci=FALSE,cut=0.1,v2=NULL,v3=NULL){

View File

@ -7,9 +7,6 @@
#' @param data dataframe to draw variables from. #' @param data dataframe to draw variables from.
#' @keywords ppv npv sensitivity specificity #' @keywords ppv npv sensitivity specificity
#' @export #' @export
#' @examples
#' rep_epi_tests()
rep_epi_tests<-function(gold,test,data){ rep_epi_tests<-function(gold,test,data){
require(epiR) require(epiR)

View File

@ -5,20 +5,19 @@
#' @param vars variables in model. Input as c() of columnnames, use dput(). #' @param vars variables in model. Input as c() of columnnames, use dput().
#' @param string variables to test. Input as c() of columnnames, use dput(). #' @param string variables to test. Input as c() of columnnames, use dput().
#' @param ci flag to get results as OR with 95% confidence interval. #' @param ci flag to get results as OR with 95% confidence interval.
#' @param data data frame to pull variables from. #' @param data dataframe to pull variables from.
#' @param fixed.var flag to set "vars" as fixed in the model. When FALSE, then true bivariate logistic regression is performed. #' @param fixed.var flag to set "vars" as fixed in the model. When FALSE, then true bivariate logistic regression is performed.
#' @keywords logistic #' @keywords logistic
#' @export #' @export
#' @examples
#' rep_glm()
rep_glm<-function(meas,vars=NULL,string,ci=FALSE,data,fixed.var=FALSE){
rep_glm<-function(meas,vars=NULL,string,ci=FALSE,data,fixed.var=FALSE)
{
## Intro and definitions
require(broom) require(broom)
y<-data[,c(meas)] y<-data[,c(meas)]
## Factor check
if(!is.factor(y)){stop("y is not a factor")} if(!is.factor(y)){stop("y is not a factor")}
## Running "true" bivariate analysis
if (fixed.var==FALSE){ if (fixed.var==FALSE){
d<-data d<-data
x<-data.frame(d[,c(vars,string)]) x<-data.frame(d[,c(vars,string)])
@ -85,7 +84,7 @@ rep_glm<-function(meas,vars=NULL,string,ci=FALSE,data,fixed.var=FALSE){
r<-data.frame(df[,1:2],pa,t)[-1,] r<-data.frame(df[,1:2],pa,t)[-1,]
} }
## Running multivariate analyses (eg "bivariate" analyses with fixed variables)
if (fixed.var==TRUE){ if (fixed.var==TRUE){
d<-data d<-data
x<-data.frame(d[,c(string)]) x<-data.frame(d[,c(string)])

View File

@ -5,12 +5,10 @@
#' @param vars variables in model. Input as c() of columnnames, use dput(). #' @param vars variables in model. Input as c() of columnnames, use dput().
#' @param string variables to test. Input as c() of columnnames, use dput(). #' @param string variables to test. Input as c() of columnnames, use dput().
#' @param ci flag to get results as OR with 95% confidence interval. #' @param ci flag to get results as OR with 95% confidence interval.
#' @param fixed.var flag to set "vars" as fixed in the model. When FALSE, then true bivariate linear regression is performed.
#' @param data data frame to pull variables from. #' @param data data frame to pull variables from.
#' @keywords linear #' @param fixed.var flag to set "vars" as fixed in the model. When FALSE, then true bivariate linear regression is performed.
#' @keywords linear regression
#' @export #' @export
#' @examples
#' rep_lm()
rep_lm<-function(meas,vars=NULL,string,ci=FALSE,data,fixed.var=FALSE){ rep_lm<-function(meas,vars=NULL,string,ci=FALSE,data,fixed.var=FALSE){

View File

@ -5,12 +5,9 @@
#' @param vars variables in model. Input as c() of columnnames, use dput(). #' @param vars variables in model. Input as c() of columnnames, use dput().
#' @param string variables to test. Input as c() of columnnames, use dput(). #' @param string variables to test. Input as c() of columnnames, use dput().
#' @param ci flag to get results as OR with 95% confidence interval. #' @param ci flag to get results as OR with 95% confidence interval.
#' @param dta data frame to pull variables from. #' @param data data frame to pull variables from.
#' @keywords olr #' @keywords olr
#' @export #' @export
#' @examples
#' rep_olr()
rep_olr<-function(meas,vars,string,ci=FALSE,data){ rep_olr<-function(meas,vars,string,ci=FALSE,data){

View File

@ -6,9 +6,6 @@
#' @param dta data frame to pull variables from. #' @param dta data frame to pull variables from.
#' @keywords olr #' @keywords olr
#' @export #' @export
#' @examples
#' rep_olr_sngl()
rep_olr_sngl<-function(meas,vars,data){ rep_olr_sngl<-function(meas,vars,data){
require(MASS) require(MASS)

View File

@ -9,8 +9,6 @@
#' @param cut cut value for gating if including or dropping the tested variable. As suggested bu S. Greenland (1989). #' @param cut cut value for gating if including or dropping the tested variable. As suggested bu S. Greenland (1989).
#' @keywords estimate-in-estimate #' @keywords estimate-in-estimate
#' @export #' @export
#' @examples
#' rep_reg_cie()
rep_reg_cie<-function(meas,vars,string,data,cut=0.1){ rep_reg_cie<-function(meas,vars,string,data,cut=0.1){

View File

@ -9,8 +9,6 @@
#' @param dec decimals for results, standard is set to 2. Mean and sd is dec-1. pval has 3 decimals. #' @param dec decimals for results, standard is set to 2. Mean and sd is dec-1. pval has 3 decimals.
#' @keywords strobe #' @keywords strobe
#' @export #' @export
#' @examples
#' strobe_diff_bygroup()
strobe_diff_bygroup<-function(meas,var,group,adj,data,dec=2){ strobe_diff_bygroup<-function(meas,var,group,adj,data,dec=2){

View File

@ -9,8 +9,6 @@
#' @param dec decimals for results, standard is set to 2. Mean and sd is dec-1. #' @param dec decimals for results, standard is set to 2. Mean and sd is dec-1.
#' @keywords strobe #' @keywords strobe
#' @export #' @export
#' @examples
#' strobe_diff_byvar()
strobe_diff_byvar<-function(meas,var,group,adj,data,dec=2){ strobe_diff_byvar<-function(meas,var,group,adj,data,dec=2){

View File

@ -8,8 +8,6 @@
#' @param dec decimals for results, standard is set to 2. Mean and sd is dec-1. #' @param dec decimals for results, standard is set to 2. Mean and sd is dec-1.
#' @keywords strobe #' @keywords strobe
#' @export #' @export
#' @examples
#' strobe_diff_twodim()
strobe_diff_twodim<-function(meas,group,adj,data,dec=2){ strobe_diff_twodim<-function(meas,group,adj,data,dec=2){
## meas: sdmt ## meas: sdmt

View File

@ -8,8 +8,6 @@
#' @param dec decimals for results, standard is set to 2. Mean and sd is dec-1. #' @param dec decimals for results, standard is set to 2. Mean and sd is dec-1.
#' @keywords logistic #' @keywords logistic
#' @export #' @export
#' @examples
#' strobe_log()
strobe_log<-function(meas,var,adj,data,dec=2){ strobe_log<-function(meas,var,adj,data,dec=2){
## Ønskeliste: ## Ønskeliste:

View File

@ -7,8 +7,6 @@
#' @param dec decimals for results, standard is set to 2. Mean and sd is dec-1. #' @param dec decimals for results, standard is set to 2. Mean and sd is dec-1.
#' @keywords olr #' @keywords olr
#' @export #' @export
#' @examples
#' strobe_olr()
strobe_olr<-function(meas,vars,data,dec=2){ strobe_olr<-function(meas,vars,data,dec=2){

View File

@ -8,8 +8,6 @@
#' @param n.by.adj flag to indicate wether to count number of patients in adjusted model or overall for outcome meassure not NA. #' @param n.by.adj flag to indicate wether to count number of patients in adjusted model or overall for outcome meassure not NA.
#' @keywords logistic #' @keywords logistic
#' @export #' @export
#' @examples
#' strobe_pred()
strobe_pred<-function(meas,adj,data,dec=2,n.by.adj=FALSE){ strobe_pred<-function(meas,adj,data,dec=2,n.by.adj=FALSE){
## Ønskeliste: ## Ønskeliste:

View File

@ -19,3 +19,4 @@ BuildType: Package
PackageUseDevtools: Yes PackageUseDevtools: Yes
PackageInstallArgs: --no-multiarch --with-keep.source PackageInstallArgs: --no-multiarch --with-keep.source
PackageCheckArgs: --as-cran PackageCheckArgs: --as-cran
PackageRoxygenize: rd,collate,namespace,vignette

View File

@ -18,7 +18,4 @@ col_fact(string, data, levels = NULL, labels = NULL)
\description{ \description{
Depending on dply's contains()-function. Depending on dply's contains()-function.
} }
\examples{
col_fact()
}
\keyword{factor} \keyword{factor}

View File

@ -14,7 +14,4 @@ col_num(string, data)
\description{ \description{
Depending on dply's contains()-function. Depending on dply's contains()-function.
} }
\examples{
col_num()
}
\keyword{numeric} \keyword{numeric}

View File

@ -11,12 +11,9 @@ comb_olr(meas, vars, data)
\item{vars}{variables in model. Input as c() of columnnames, use dput().} \item{vars}{variables in model. Input as c() of columnnames, use dput().}
\item{dta}{data frame to pull variables from.} \item{data}{data frame to pull variables from.}
} }
\description{ \description{
Should be combined with "rep_olr()". The confint() function is rather slow, causing the whole function to hang when including many predictors and calculating the ORs with CI. Should be combined with "rep_olr()". The confint() function is rather slow, causing the whole function to hang when including many predictors and calculating the ORs with CI.
} }
\examples{
comb_olr()
}
\keyword{olr} \keyword{olr}

View File

@ -12,7 +12,4 @@ date_convert(x)
\description{ \description{
Input format as dd/mm/yyyy, output is standard yyyy-mm-dd Input format as dd/mm/yyyy, output is standard yyyy-mm-dd
} }
\examples{
date_convert()
}
\keyword{date} \keyword{date}

View File

@ -14,7 +14,4 @@ hwe_allele(x, y)
\description{ \description{
For easy calculation. For easy calculation.
} }
\examples{
hwe_allele()
}
\keyword{hardy-weinberg-equllibrium} \keyword{hardy-weinberg-equllibrium}

View File

@ -12,7 +12,4 @@ hwe_geno(mm, mn, nn, mo, no, oo, alleles = 2)
\description{ \description{
For easy calculation. For easy calculation.
} }
\examples{
hwe_geno()
}
\keyword{hardy-weinberg-equllibrium} \keyword{hardy-weinberg-equllibrium}

View File

@ -16,7 +16,4 @@ hwe_sum(a1, a2, f)
\description{ \description{
For easy printing. For easy printing.
} }
\examples{
hwe_sum()
}
\keyword{hardy-weinberg-equllibrium} \keyword{hardy-weinberg-equllibrium}

View File

@ -28,7 +28,4 @@ plot_ord_odds(x, title = NULL, dec = 3, lbls = NULL,
\description{ \description{
Heavily inspired by https://www.r-bloggers.com/plotting-odds-ratios-aka-a-forrestplot-with-ggplot2/ Heavily inspired by https://www.r-bloggers.com/plotting-odds-ratios-aka-a-forrestplot-with-ggplot2/
} }
\examples{
plot_ord_odds()
}
\keyword{forestplot} \keyword{forestplot}

View File

@ -23,8 +23,5 @@ rep_biv(y, v1, string, data, method = "pval", logistic = FALSE,
\description{ \description{
For bivariate analyses, for gating by p-value or change-in-estimate. For bivariate analyses, for gating by p-value or change-in-estimate.
} }
\examples{
rep_biv()
}
\keyword{logistic} \keyword{logistic}
\keyword{regression} \keyword{regression}

View File

@ -19,9 +19,6 @@ For bivariate analyses. The confint() function is rather slow, causing the whole
\details{ \details{
Repeats the epi.tests from the epiR package. Either gs or test should be of length 1. Repeats the epi.tests from the epiR package. Either gs or test should be of length 1.
} }
\examples{
rep_epi_tests()
}
\keyword{npv} \keyword{npv}
\keyword{ppv} \keyword{ppv}
\keyword{sensitivity} \keyword{sensitivity}

View File

@ -16,14 +16,11 @@ rep_glm(meas, vars = NULL, string, ci = FALSE, data,
\item{ci}{flag to get results as OR with 95% confidence interval.} \item{ci}{flag to get results as OR with 95% confidence interval.}
\item{data}{data frame to pull variables from.} \item{data}{dataframe to pull variables from.}
\item{fixed.var}{flag to set "vars" as fixed in the model. When FALSE, then true bivariate logistic regression is performed.} \item{fixed.var}{flag to set "vars" as fixed in the model. When FALSE, then true bivariate logistic regression is performed.}
} }
\description{ \description{
For bivariate analyses. The confint() function is rather slow, causing the whole function to hang when including many predictors and calculating the ORs with CI. For bivariate analyses. The confint() function is rather slow, causing the whole function to hang when including many predictors and calculating the ORs with CI.
} }
\examples{
rep_glm()
}
\keyword{logistic} \keyword{logistic}

View File

@ -23,7 +23,5 @@ rep_lm(meas, vars = NULL, string, ci = FALSE, data,
\description{ \description{
For bivariate analyses, to determine which variables to include in adjusted model. For bivariate analyses, to determine which variables to include in adjusted model.
} }
\examples{
rep_lm()
}
\keyword{linear} \keyword{linear}
\keyword{regression}

View File

@ -15,12 +15,9 @@ rep_olr(meas, vars, string, ci = FALSE, data)
\item{ci}{flag to get results as OR with 95% confidence interval.} \item{ci}{flag to get results as OR with 95% confidence interval.}
\item{dta}{data frame to pull variables from.} \item{data}{data frame to pull variables from.}
} }
\description{ \description{
For bivariate analyses. The confint() function is rather slow, causing the whole function to hang when including many predictors and calculating the ORs with CI. For bivariate analyses. The confint() function is rather slow, causing the whole function to hang when including many predictors and calculating the ORs with CI.
} }
\examples{
rep_olr()
}
\keyword{olr} \keyword{olr}

View File

@ -16,7 +16,4 @@ rep_olr_sngl(meas, vars, data)
\description{ \description{
Should be combined with "rep_olr()". For bivariate analyses. The confint() function is rather slow, causing the whole function to hang when including many predictors and calculating the ORs with CI. Should be combined with "rep_olr()". For bivariate analyses. The confint() function is rather slow, causing the whole function to hang when including many predictors and calculating the ORs with CI.
} }
\examples{
rep_olr_sngl()
}
\keyword{olr} \keyword{olr}

View File

@ -22,7 +22,4 @@ rep_reg_cie(meas, vars, string, data, cut = 0.1)
\description{ \description{
For bivariate analyses, binary logistic or linear regression. From "Modeling and variable selection in epidemiologic analysis." - S. Greenland, 1989. For bivariate analyses, binary logistic or linear regression. From "Modeling and variable selection in epidemiologic analysis." - S. Greenland, 1989.
} }
\examples{
rep_reg_cie()
}
\keyword{estimate-in-estimate} \keyword{estimate-in-estimate}

View File

@ -22,7 +22,4 @@ strobe_diff_bygroup(meas, var, group, adj, data, dec = 2)
\description{ \description{
Printable table of three dimensional regression analysis of group vs var for meas. By group. Printable table of three dimensional regression analysis of group vs var for meas. By group.
} }
\examples{
strobe_diff_bygroup()
}
\keyword{strobe} \keyword{strobe}

View File

@ -22,7 +22,4 @@ strobe_diff_byvar(meas, var, group, adj, data, dec = 2)
\description{ \description{
Printable table of three dimensional regression analysis of group vs var for meas. By var. Includes p-values. Printable table of three dimensional regression analysis of group vs var for meas. By var. Includes p-values.
} }
\examples{
strobe_diff_byvar()
}
\keyword{strobe} \keyword{strobe}

View File

@ -20,7 +20,4 @@ strobe_diff_twodim(meas, group, adj, data, dec = 2)
\description{ \description{
Printable table of regression analysis by group for meas. Detects wether to perform logistic or linear regression. Printable table of regression analysis by group for meas. Detects wether to perform logistic or linear regression.
} }
\examples{
strobe_diff_twodim()
}
\keyword{strobe} \keyword{strobe}

View File

@ -20,7 +20,4 @@ strobe_log(meas, var, adj, data, dec = 2)
\description{ \description{
Printable table of logistic regression analysis according to STROBE. Printable table of logistic regression analysis according to STROBE.
} }
\examples{
strobe_log()
}
\keyword{logistic} \keyword{logistic}

View File

@ -18,7 +18,4 @@ strobe_olr(meas, vars, data, dec = 2)
\description{ \description{
Printable table of logistic regression analysis oaccording to STROBE. Printable table of logistic regression analysis oaccording to STROBE.
} }
\examples{
strobe_olr()
}
\keyword{olr} \keyword{olr}

View File

@ -20,7 +20,4 @@ strobe_pred(meas, adj, data, dec = 2, n.by.adj = FALSE)
\description{ \description{
Printable table of logistic regression analysis according to STROBE. Printable table of logistic regression analysis according to STROBE.
} }
\examples{
strobe_pred()
}
\keyword{logistic} \keyword{logistic}

View File

@ -1,13 +0,0 @@
library(roxygen2)
library(devtools)
source("/Users/andreas/Documents/GitHub/daDoctoR/updatePackageVersion.R")
setwd("/Users/andreas/Documents/GitHub/daDoctoR")
updatePackageVersion()
document()
# Inspiration: "https://hilaryparker.com/2014/04/29/writing-an-r-package-from-scratch/"

View File

@ -1,3 +0,0 @@
## Looking for errors in code
for (f in list.files("/Users/andreas/Documents/GitHub/daDoctoR/R", full.names=TRUE)) parse(f)

View File

@ -1,13 +0,0 @@
# Install new version
# Remove
remove.packages("daDoctoR")
.rs.restartR()
setwd("/")
devtools::install_github('agdamsbo/daDoctoR')
library(daDoctoR)

View File

@ -1,35 +0,0 @@
updatePackageVersion <- function(packageLocation ="."){
## Seen at: https://www.mango-solutions.com/blog/how-to-auto-update-a-package-version-number
## Read DESCRIPTION file
desc <- readLines(file.path(packageLocation, "DESCRIPTION"))
## Find the line where the version is defined
vLine <- grep("^Version\\:", desc)
## Extract version number
vNumber <- gsub("^Version\\:\\s*", "", desc[vLine])
## Split the version number into two; a piece to keep, a piece to increment
versionNumber <- strsplit(vNumber, "\\.")[[1]]
versionParts <- length(versionNumber)
vNumberKeep <- paste(versionNumber[1:(versionParts-1)], sep= "", collapse= ".")
vNumberUpdate <- versionNumber[versionParts]
## Replace old version number with new one (increment by 1)
oldVersion <- as.numeric(vNumberUpdate)
newVersion <- oldVersion + 1
## Build final version number
vFinal <- paste(vNumberKeep, newVersion, sep = ".")
## Update DESCRIPTION file (in R)
desc[vLine] <- paste0("Version: ", vFinal )
## Update the actual DESCRIPTION file
writeLines(desc, file.path(packageLocation, "DESCRIPTION"))
## Return the updated version number to screen
return(vFinal)
}