Description Usage Arguments Details Author(s) Examples
Gets survey means svymean
, standard error and
confidence interval estimates of adult_weight
or child_weight
.
1 2 3 4 |
model |
(list) List from Optional |
meanvars |
(vector) Strings indicating which variables are required to estimate the mean. |
days |
(vector) Vector of days in which to compute the estimates |
group |
(vector) Variable in which to group the results. |
design |
A |
confidence |
(numeric) Confidence level ( |
The default design
is that of simple random sampling.
Dalia Camacho-García-Formentí daliaf172@gmail.com
Rodrigo Zepeda-Tello rzepeda17@gmail.com
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | #EXAMPLE 1A: RANDOM SAMPLE MODELLING FOR ADULTS
#--------------------------------------------------------
#Antropometric data
models <- c(45, 67, 58, 92, 81)
heights <- c(1.30, 1.73, 1.77, 1.92, 1.73)
ages <- c(45, 23, 66, 44, 23)
sexes <- c("male", "female", "female", "male", "male")
#Matrix of energy consumption reduction:
EIchange <- rbind(rep(-100, 365), rep(-200, 365), rep(-200, 365),
rep(-123, 365), rep(-50, 365))
#Create model change model
model_model <- adult_weight(models, heights, ages, sexes,
EIchange)
#Calculate survey mean and variance for 25 days
aggregate_data <- model_mean(model_model)
#You can plot the mean with ci
if(require(ggplot2)){
ggplot(subset(aggregate_data, variable == "Body_Weight")) +
geom_line(aes(x = time, y = mean)) +
geom_line(aes(x = time, y = Lower_CI_mean), linetype = "dashed") +
geom_line(aes(x = time, y = Upper_CI_mean), linetype = "dashed") +
theme_classic() + xlab("Days") + ylab("Mean Body model (kg)")
}
#EXAMPLE 1C: RANDOM SAMPLE MODELLING FOR CHILDREN
#--------------------------------------------------------
#Antropometric data
FatFree <- c(32, 17.2, 18.8, 20, 24.1)
Fat <- c(4.30, 2.02, 3.07, 1.12, 2.93)
ages <- c(10, 6.2, 5.4, 4, 4.1)
sexes <- c("male", "female", "female", "male", "male")
#Returns a model change matrix and other matrices
model_model <- child_weight(ages, sexes, Fat, FatFree)
#Calculate survey mean and variance for 25 days
aggregate_data <- model_mean(model_model)
#You can plot the mean with ci
if(require(ggplot2)){
ggplot(subset(aggregate_data, variable == "Body_Weight")) +
geom_line(aes(x = time, y = mean)) +
geom_line(aes(x = time, y = Lower_CI_mean), linetype = "dashed") +
geom_line(aes(x = time, y = Upper_CI_mean), linetype = "dashed") +
theme_classic() + xlab("Days") + ylab("Mean Body model (kg)")
}
#EXAMPLE 2A: SURVEY DATA FOR ADULTS
#-------------------------------------------------------
#Data frame for use in survey
probs <- runif(10, 20, 60)
datasvy <- data.frame(
id = 1:10,
bw = runif(10,60,90),
ht = runif(10, 1.5, 2),
age = runif(10, 18, 80),
sex = sample(c("male","female"),10, replace = TRUE),
kcal = runif(10, 2000, 3000),
group = sample(c(0,1), 10, replace = TRUE),
svyw = probs/sum(probs))
#Days
days <- 365
#Energy intake matrix
EIchange <- matrix(NA, nrow = 0, ncol = days)
for(i in 1:nrow(datasvy)){
EIchange <- rbind(EIchange, rep(datasvy$kcal[i], days))
}
#Calculate model change
svymodel <- adult_weight(datasvy$bw, datasvy$ht, datasvy$age,
datasvy$sex, EIchange)
#Create survey design using survey package
design <- survey::svydesign(id = ~id, models = datasvy$svyw,
data = datasvy)
#Group to calculate means
group <- datasvy$group
#Calculate survey mean and variance for 25 days
aggregate_data <- model_mean(svymodel, design = design, group = group)
#You can plot the mean with ci
if(require(ggplot2)){
ggplot(subset(aggregate_data, variable == "Body_Weight")) +
geom_ribbon(aes(x = time, ymin = Lower_CI_mean, ymax = Upper_CI_mean,
fill = factor(group)), alpha = 0.25) +
geom_line(aes(x = time, y = mean, color = factor(group)), size = 2) +
theme_classic() + xlab("Days") + ylab("Mean Body model (kg)")
}
#EXAMPLE 2A: SURVEY DATA FOR CHILDREN
#-------------------------------------------------------
#Data frame for use in survey
probs <- runif(10, 20, 60)
datasvy <- data.frame(
id = 1:10,
age = runif(10, 2, 12),
sex = sample(c("male","female"),10, replace = TRUE),
fat = runif(10, 2, 10),
fatfree = runif(10, 8, 15),
group = sample(c(0,1), 10, replace = TRUE),
svyw = probs/sum(probs))
#Days
days <- 365
#Calculate model change
svymodel <- child_weight(datasvy$age, datasvy$sex, datasvy$fat, datasvy$fatfree)
#Create survey design using survey package
design <- survey::svydesign(id = ~id, models = datasvy$svyw,
data = datasvy)
#Group to calculate means
group <- datasvy$group
#Calculate survey mean and variance for 25 days
aggregate_data <- model_mean(svymodel, design = design, group = group)
#You can plot the mean with ci
if(require(ggplot2)){
ggplot(subset(aggregate_data, variable == "Body_Weight")) +
geom_ribbon(aes(x = time, ymin = Lower_CI_mean, ymax = Upper_CI_mean,
fill = factor(group)), alpha = 0.25) +
geom_line(aes(x = time, y = mean, color = factor(group)), size = 2) +
theme_classic() + xlab("Days") + ylab("Mean Body Weight (kg)")
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.