Thanks Mara .. Here you go ..Kindly let me know if you find the bug
setwd('P:/Staff/Ravi Deepak/Optimum Windows/R_Code')
.libPaths('P:/Staff/Ravi Deepak/R libraries/R3UserLibs')
require(ggplot2)
#> Loading required package: ggplot2
#> Warning: package 'ggplot2' was built under R version 3.4.4
require(GGally)
#> Loading required package: GGally
#> Warning: package 'GGally' was built under R version 3.4.4
require(reshape2)
#> Loading required package: reshape2
require(lme4)
#> Loading required package: lme4
#> Warning: package 'lme4' was built under R version 3.4.4
#> Loading required package: Matrix
require(compiler)
#> Loading required package: compiler
require(parallel)
#> Loading required package: parallel
require(boot)
#> Loading required package: boot
require(lattice)
#> Loading required package: lattice
#>
#> Attaching package: 'lattice'
#> The following object is masked from 'package:boot':
#>
#> melanoma
require(xlsx)
#> Loading required package: xlsx
#> Warning: package 'xlsx' was built under R version 3.4.3
#> Loading required package: rJava
#> Loading required package: xlsxjars
library(reprex)
#> Warning: package 'reprex' was built under R version 3.4.4
data <- read.xlsx("probabilisticanalysisdata.xlsx", sheetName = "StrideT")
as.data.frame (data)
#> Mean_P Mean_C SD_P SD_C LowOPt HighOpt SampleSize_P SampleSize_C
#> 1 3.30 1.60 2.500 1.4000 1.06 2.34 34 22
#> 2 3.10 1.70 1.200 0.5000 NA NA 19 22
#> 3 4.81 2.33 4.690 0.6700 NA NA 25 10
#> 4 2.80 2.30 0.900 0.7000 NA NA 35 22
#> 5 5.00 1.30 2.500 1.0000 NA NA 14 69
#> 6 2.70 2.10 1.200 1.3000 NA NA 33 44
#> 7 2.90 2.30 1.200 1.0000 NA NA 43 47
#> 8 5.51 4.75 5.100 2.3000 NA NA 21 58
#> 9 5.09 2.93 1.980 0.7100 NA NA 5 4
#> 10 4.80 3.22 1.420 1.2400 NA NA 10 6
#> 11 8.66 1.67 10.450 0.6400 NA NA 15 15
#> 12 6.28 1.67 3.460 0.6400 NA NA 15 15
#> 13 4.40 2.10 3.000 0.9000 NA NA 17 57
#> 14 1.90 1.80 0.900 1.1400 NA NA 22 22
#> 15 2.40 2.30 0.900 1.2000 NA NA 30 30
#> 16 4.80 2.30 2.100 1.2000 NA NA 20 30
#> 17 3.90 2.30 1.700 1.2000 NA NA 20 30
#> 18 2.24 1.94 0.740 0.3600 NA NA 36 30
#> 19 3.39 3.13 1.850 2.4600 NA NA 40 43
#> 20 4.40 2.30 2.100 0.5000 NA NA 15 16
#> 21 7.60 2.30 5.600 0.5000 NA NA 20 16
#> 22 4.50 2.30 0.600 0.5000 NA NA 11 16
#> 23 2.90 2.40 1.300 0.6000 NA NA 23 18
#> 24 2.60 1.80 1.000 0.6000 NA NA 29 26
#> 25 2.38 1.39 0.530 0.1400 NA NA 9 10
#> 26 2.20 1.40 1.200 0.3000 NA NA 9 9
#> 27 2.30 2.00 0.800 0.8000 NA NA 45 22
#> 28 9.88 3.51 5.280 0.8800 NA NA 15 14
#> 29 4.20 2.95 2.700 1.7700 NA NA 13 13
#> 30 3.90 2.70 1.500 1.0000 NA NA 11 11
#> 31 7.03 4.26 1.454 1.6038 NA NA 29 89
#> 32 2.55 2.23 0.780 0.7600 NA NA 21 21
#> 33 5.71 1.79 2.000 0.3800 NA NA 5 5
#> 34 3.50 2.40 1.900 1.8000 NA NA 40 51
#> 35 2.33 2.29 0.960 0.5700 NA NA 10 14
#> 36 2.34 2.30 0.960 0.5300 NA NA 10 14
#> 37 1.98 1.49 0.710 0.4800 NA NA 22 17
#> 38 2.11 1.72 0.730 0.4600 NA NA 30 28
#> 39 1.93 1.80 0.570 0.5400 NA NA 20 20
#> 40 1.45 1.06 0.330 0.1800 NA NA 18 15
#> SEM_P SEM_C Wgt_P Wgt_C StudyNo
#> 1 0.42874646 0.29848100 2.3323808 3.350297 1
#> 2 0.27529888 0.10660036 3.6324158 9.380832 2
#> 3 0.93800000 0.21187260 1.0660981 4.719817 3
#> 4 0.15212777 0.14924050 6.5734220 6.700594 4
#> 5 0.66815310 0.12038585 1.4966630 8.306624 5
#> 6 0.20889319 0.19598237 4.7871355 5.102500 6
#> 7 0.18299828 0.14586499 5.4645321 6.855655 7
#> 8 1.11291124 0.30200480 0.8985443 3.311206 8
#> 9 0.88548292 0.35500000 1.1293273 2.816901 9
#> 10 0.44904343 0.50622788 2.2269561 1.975395 10
#> 11 2.69817840 0.16524729 0.3706204 6.051536 11
#> 12 0.89336816 0.16524729 1.1193593 6.051536 12
#> 13 0.72760688 0.11920791 1.3743685 8.388705 13
#> 14 0.19188064 0.24304882 5.2115731 4.114400 14
#> 15 0.16431677 0.21908902 6.0858062 4.564355 15
#> 16 0.46957428 0.21908902 2.1295885 4.564355 16
#> 17 0.38013156 0.21908902 2.6306682 4.564355 17
#> 18 0.12333333 0.06572671 8.1081081 15.214515 18
#> 19 0.29251068 0.37514648 3.4186786 2.665625 19
#> 20 0.54221767 0.12500000 1.8442778 8.000000 20
#> 21 1.25219807 0.12500000 0.7985957 8.000000 21
#> 22 0.18090681 0.12500000 5.5277080 8.000000 22
#> 23 0.27106874 0.14142136 3.6891012 7.071068 23
#> 24 0.18569534 0.11766968 5.3851648 8.498366 24
#> 25 0.17666667 0.04427189 5.6603774 22.587698 25
#> 26 0.40000000 0.10000000 2.5000000 10.000000 26
#> 27 0.11925696 0.17056057 8.3852549 5.863020 27
#> 28 1.36329014 0.23518989 0.7335196 4.251883 28
#> 29 0.74884526 0.49090967 1.3353894 2.037035 29
#> 30 0.45226702 0.30151134 2.2110832 3.316625 30
#> 31 0.27000102 0.17000246 3.7036897 5.882268 31
#> 32 0.17020995 0.16584560 5.8750970 6.029705 32
#> 33 0.89442719 0.16994117 1.1180340 5.884389 33
#> 34 0.30041638 0.25205042 3.3287133 3.967460 34
#> 35 0.30357866 0.15233891 3.2940392 6.564311 35
#> 36 0.30357866 0.14164846 3.2940392 7.059731 36
#> 37 0.15137251 0.11641710 6.6062194 8.589803 37
#> 38 0.13327916 0.08693183 7.5030487 11.503267 38
#> 39 0.12745587 0.12074767 7.8458526 8.281733 39
#> 40 0.07778175 0.04647580 12.8564869 21.516574 40
zeros <- matrix(0,40,1)
ones <- matrix(1,40,1)
data_P <- data[c(1,11,13)]
data_C <- data[c(2,12,13)]
data_P <- cbind(data_P,zeros)
data_C <- cbind(data_C,ones)
names(data_P) <- c("Stridetime","Weight","StudyNo","Category")
names(data_C) <- c("Stridetime","Weight","StudyNo","Category")
dataforreg <- rbind(data_P,data_C)
#Mixed GLMM Model
mixed <- glmer(Category ~ Stridetime + (1|StudyNo), family=binomial(logit), dataforreg,weights = dataforreg$Weight)
#> Warning in eval(family$initialize, rho): non-integer #successes in a
#> binomial glm!
#> Error in pwrssUpdate(pp, resp, tol = tolPwrss, GQmat = GQmat, compDev = compDev, : (maxstephalfit) PIRLS step-halvings failed to reduce deviance in pwrssUpdate
fixed <- glm(Category~ Stridetime,family=binomial(logit), dataforreg,weights = dataforreg$Weight)
#> Warning in eval(family$initialize): non-integer #successes in a binomial
#> glm!
ROC Curve
prob=predict(mixed,type=c("response"))
#> Error in predict(mixed, type = c("response")): object 'mixed' not found
dataforreg$prob=prob
#> Error in eval(expr, envir, enclos): object 'prob' not found
library(pROC)
#> Warning: package 'pROC' was built under R version 3.4.4
#> Type 'citation("pROC")' for a citation.
#>
#> Attaching package: 'pROC'
#> The following objects are masked from 'package:stats':
#>
#> cov, smooth, var
g <- roc(Category ~ prob, data = dataforreg)
#> Error in eval(predvars, data, env): object 'prob' not found
coords(g, "b", ret="t", best.method="closest.topleft")
#> Error in coords(g, "b", ret = "t", best.method = "closest.topleft"): object 'g' not found
plot(g, print.thres="best", print.thres.best.method="closest.topleft")
#> Error in plot(g, print.thres = "best", print.thres.best.method = "closest.topleft"): object 'g' not found
##########################################################################
invlog <- exp( coef(fixed) ) / ( 1 + exp( coef(fixed) ) )
#Predicting the models
options(na.action = "na.fail")
dredge.models<-dredge(mixed,trace=FALSE,rank="AICc")
my.dredge.models<-get.models(dredge.models,subset =TRUE)
silly<-model.avg(my.dredge.models,subset=delta<10)
predict(silly,type="response")