J'utilise une base de données (bdd) pondérées et je voudrais créer une fonction me permettant d'obtenir un tableau simple avec les proportions et les intervalles de confiance voulues pour remplacer ce code : (bdd = base de donnée, CS7 = nom d'une variable, pond = variable des poids)
Code : Tout sélectionner
dw <- svydesign(ids=~1,data=bdd,weights=~bdd$pond
options(digits=3)
f <- freq(svytable(~CS7,dw))
n % val%
1 40637 25.4 25.4
2 118657 74.1 74.1
999 919 0.6 0.6
VIDE 23 0.0 0.0
prop1 <- svyciprop(~I(CS7==1),dw)
prop2 <- svyciprop(~I(CS7==2),dw)
prop3 <- svyciprop(~I(CS7==999),dw)
prop4 <- svyciprop(~I(CS7==VIDE),dw)
x <- matrix(c(f[1,1],prop1[1],confint(prop1),f[2,1],prop2[1],confint(prop2),f[3,1],prop3[1],confint(prop3),f[4,1],prop4[1],confint(prop4)),nrow=4,byrow=T)
X <- data.frame(x)
names(X) <- c("Nb", "%", "IC-", "IC+")
> X
Nb % IC- IC+
1 40637 25.3606 22.14874 28.865
2 118657 74.0517 70.54422 77.276
3 919 0.5734 0.31790 1.032
4 23 0.0143 0.00202 0.102
Je commence à écrire ma fonction et j'ai déjà une erreur :
PropIC = function(bdd,VarA)
{ dw <- svydesign(ids=~1,data=bdd,weights=~bdd$pond)
f <- freq(svytable(~VarA,dw),total=T)
return (f)
}
Code : Tout sélectionner
> PropIC(bdd,CS7)
Error in eval(expr, envir, enclos) : object 'VarA' not found
Called from: eval(expr, envir, enclos)
Browse[1]>
Idem en faisant PropIC(bdd,bdd$CS7)
Est-ce que quelqu'un saurait d'où provient ce problème ?
Merci,