mirror of
https://github.com/agdamsbo/daDoctoR.git
synced 2024-11-22 03:40:23 +01:00
trying to fix warnings
This commit is contained in:
parent
7b5888e96d
commit
054dd78c43
46
R/rep_lm.R
46
R/rep_lm.R
@ -9,15 +9,7 @@
|
||||
#' @keywords linear regression
|
||||
#' @export
|
||||
#' @examples
|
||||
#' l<-50
|
||||
#' y<-factor(rep(c("a","b"),l))
|
||||
#' x<-rnorm(length(y), mean=50, sd=10)
|
||||
#' v1<-factor(rep(c("r","s"),length(y)/2))
|
||||
#' v2<-sample(1:100, length(y), replace=FALSE)
|
||||
#' v3<-as.numeric(1:length(y))
|
||||
#' d<-data.frame(y,x,v1,v2,v3)
|
||||
#' preds<-c("v1","v2","v3")
|
||||
#' rep_lm(meas="x",vars="y",string=preds,ci=F,data=d)
|
||||
#' rep_lm()
|
||||
|
||||
rep_lm<-function(meas,vars,string,ci=FALSE,data){
|
||||
|
||||
@ -26,12 +18,14 @@ rep_lm<-function(meas,vars,string,ci=FALSE,data){
|
||||
d<-data
|
||||
x<-data.frame(d[,c(string)])
|
||||
v<-data.frame(d[,c(vars)])
|
||||
names(v)<-c(vars)
|
||||
|
||||
y<-d[,c(meas)]
|
||||
dt<-cbind(y,v)
|
||||
dt<-cbind(y=y,v)
|
||||
m1<-length(coef(lm(y~.,data = dt)))
|
||||
|
||||
if (is.factor(y)){stop("Some kind of error message would be nice, but y should not be a factor!")}
|
||||
names(v)<-c(vars)
|
||||
|
||||
if (is.factor(y)){stop("y should not be a factor!")}
|
||||
|
||||
if (ci==TRUE){
|
||||
|
||||
@ -42,8 +36,9 @@ rep_lm<-function(meas,vars,string,ci=FALSE,data){
|
||||
dat<-cbind(dt,x[,i])
|
||||
m<-lm(y~.,data=dat)
|
||||
|
||||
l<-suppressMessages(round(confint(m)[-c(1:m1),1],2))
|
||||
u<-suppressMessages(round(confint(m)[-c(1:m1),2],2))
|
||||
ci<-suppressMessages(confint(m))
|
||||
l<-round(ci[-c(1:m1),1],2)
|
||||
u<-round(ci[-c(1:m1),2],2)
|
||||
or<-round(coef(m)[-c(1:m1)],2)
|
||||
or_ci<-paste0(or," (",l," to ",u,")")
|
||||
pv<-round(tidy(m)$p.value[-c(1:m1)],3)
|
||||
@ -56,7 +51,7 @@ rep_lm<-function(meas,vars,string,ci=FALSE,data){
|
||||
|
||||
df<-rbind(df,cbind(pred,or_ci,pv))}}
|
||||
|
||||
if (ci==FALSE){
|
||||
else {
|
||||
|
||||
df<-data.frame(matrix(NA,ncol = 3))
|
||||
names(df)<-c("pred","b","pv")
|
||||
@ -65,28 +60,20 @@ rep_lm<-function(meas,vars,string,ci=FALSE,data){
|
||||
dat<-cbind(dt,x[,i])
|
||||
|
||||
m<-lm(y~.,data=dat)
|
||||
|
||||
b<-round(coef(m)[-c(1:m1)],3)
|
||||
|
||||
pv<-round(tidy(m)$p.value[-c(1:m1)],3)
|
||||
|
||||
x1<-x[,i]
|
||||
|
||||
if (is.factor(x1)){
|
||||
pred<-paste(names(x)[i],levels(x1)[-1],sep = "_")
|
||||
}
|
||||
|
||||
else {pred<-names(x)[i]}
|
||||
|
||||
df<-rbind(df,cbind(pred,b,pv))
|
||||
|
||||
}}
|
||||
|
||||
pa<-as.numeric(df[,3])
|
||||
t <- ifelse(pa<=0.1,"include","drop")
|
||||
pa<-ifelse(pa<0.001,"<0.001",pa)
|
||||
|
||||
t <- ifelse(pa<=0.1|pa=="<0.001","include","drop")
|
||||
|
||||
pa <- ifelse(pa<=0.05|pa=="<0.001",paste0("*",pa),
|
||||
ifelse(pa>0.05&pa<=0.1,paste0(".",pa),pa))
|
||||
|
||||
@ -94,14 +81,3 @@ rep_lm<-function(meas,vars,string,ci=FALSE,data){
|
||||
|
||||
return(r)
|
||||
}
|
||||
|
||||
|
||||
l<-50
|
||||
y<-factor(rep(c("a","b"),l))
|
||||
x<-rnorm(length(y), mean=50, sd=10)
|
||||
v1<-factor(rep(c("r","s"),length(y)/2))
|
||||
v2<-sample(1:100, length(y), replace=FALSE)
|
||||
v3<-as.numeric(1:length(y))
|
||||
d<-data.frame(y,x,v1,v2,v3)
|
||||
preds<-c("v1","v2","v3")
|
||||
rep_lm(meas="x",vars="y",string=preds,ci=F,data=d)
|
||||
|
@ -100,6 +100,6 @@ strobe_diff_twodim<-function(meas,group,adj,data,dec=2){
|
||||
ls<-list(logistic.regression=df)
|
||||
}
|
||||
|
||||
invisible(ls$adjustments<-dput(names(ads)))
|
||||
ls$adjustments<-names(ads)
|
||||
return(ls)
|
||||
}
|
||||
|
@ -12,11 +12,11 @@
|
||||
#' strobe_olr()
|
||||
|
||||
strobe_olr<-function(meas,var,adj,data,dec=2){
|
||||
#' Ønskeliste:
|
||||
#'
|
||||
#' - Sum af alle, der indgår (Overall N)
|
||||
#' - Ryd op i kode, der der er overflødig %-regning, alternativt, så fiks at NA'er ikke skal regnes med.
|
||||
#'
|
||||
## Ønskeliste:
|
||||
##
|
||||
## - Sum af alle, der indgår (Overall N)
|
||||
## - Ryd op i kode, der der er overflødig %-regning, alternativt, så fiks at NA'er ikke skal regnes med.
|
||||
##
|
||||
require(MASS)
|
||||
require(dplyr)
|
||||
|
||||
|
@ -21,15 +21,7 @@ rep_lm(meas, vars, string, ci = FALSE, data)
|
||||
For bivariate analyses, to determine which variables to include in adjusted model.
|
||||
}
|
||||
\examples{
|
||||
l<-50
|
||||
y<-factor(rep(c("a","b"),l))
|
||||
x<-rnorm(length(y), mean=50, sd=10)
|
||||
v1<-factor(rep(c("r","s"),length(y)/2))
|
||||
v2<-sample(1:100, length(y), replace=FALSE)
|
||||
v3<-as.numeric(1:length(y))
|
||||
d<-data.frame(y,x,v1,v2,v3)
|
||||
preds<-c("v1","v2","v3")
|
||||
rep_lm(meas="x",vars="y",string=preds,ci=F,data=d)
|
||||
rep_lm()
|
||||
}
|
||||
\keyword{linear}
|
||||
\keyword{regression}
|
||||
|
@ -20,5 +20,8 @@ strobe_olr(meas, var, adj, data, dec = 2)
|
||||
\description{
|
||||
Printable table of linear regression analysis of group vs var for meas. By group.
|
||||
}
|
||||
\examples{
|
||||
strobe_olr()
|
||||
}
|
||||
\keyword{olr}
|
||||
\keyword{strobe}
|
||||
|
20
packing.R
Normal file
20
packing.R
Normal file
@ -0,0 +1,20 @@
|
||||
library(roxygen2)
|
||||
library(devtools)
|
||||
|
||||
# Packing for publication
|
||||
|
||||
setwd("/Users/andreas/Documents/GitHub/daDoctoR"); document()
|
||||
|
||||
|
||||
setwd(".."); install("daDoctoR")
|
||||
|
||||
# Install from GitHub
|
||||
|
||||
setwd("/"); devtools::install_github('agdamsbo/daDoctoR'); library(daDoctoR)
|
||||
|
||||
"https://hilaryparker.com/2014/04/29/writing-an-r-package-from-scratch/"
|
||||
|
||||
# Fixes
|
||||
|
||||
remove.packages("daDoctoR"); .rs.restartR()
|
||||
|
Loading…
Reference in New Issue
Block a user