[R] "xtable" results doesn't correspond to data.frame

2007-06-20 Thread Vumani Dlamini
Dear useRs,
Am trying to use xtable on the following data.frame and I don't get what I 
expect:

example.table <- data.frame(rbind(
c("Gender"," "," "," "),
cbind(rep(" ",2),c("Male","Female"),c(3.0,4.0),c(3/7,4/7))
))
colnames(example.table) <- c(" "," ","number of patients","%")
example.xtable <- xtable(example.table)
print.xtable(example.xtable, include.rownames=FALSE)

I can seem to get latex output which corresponds to the data.frame which is,
\begin{table}[ht]
\begin{center}
\begin{tabular}{}
  \hline
  &   & number of patients & \% \\
  \hline
Gender & &   &   \\
&  Male & 3 & 0.428571428571429 \\
&   Female & 4 & 0.571428571428571 \\
   \hline
\end{tabular}
\end{center}
\end{table}

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] problems with index within a strata

2007-05-28 Thread Vumani Dlamini
dear useRs,
I have several datasets which are in repeated measurements format and I 
would like to extract the first measurement for each individual. In some 
cases measurements of certain characteristics are also stacked on top of 
each other and thats where the problem lies. A prototype of the code I use 
is as follows,

# If I am extracting the first element for each individual (works fine)
temp <- sort(rpois(100,2.5))
temp.tab <- as.vector(table(temp))
cbind(temp,unlist(lapply(1:length(temp.tab), function(i){1:temp.tab[i]})))

# If I am extracting the first element of a variable for each individual 
(doesn't work)
temp.0 <- sort(rpois(100,2.5))
temp.1 <- rbinom(100,1,0.25)
temp.tab <- as.vector(t(table(temp.0,temp.1)))
cbind(temp,unlist(lapply(1:length(temp.tab), function(i){1:temp.tab[i]})))

I don't understand why the first works ok and the second fails. 
"sum(temp.tab)" is still the same.
Thanks for your help,
Vumani

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] sorting elements of matrix by row

2006-10-27 Thread Vumani Dlamini
Dear R users,
I would like to sort elements of a matrix by row and use this ordering to 
also sort another matrix. I am trying to post-order the means of components 
for a mixture model and would also like to do the same for the component 
probabilities. This is what I have tried thus far, but I doubt whether its 
efficient given the number of replications I am using:

mean.data <- matrix(rnorm(20,0,1),10,2)
probs <- runif(10)
prob.data <- cbind(probs,1-probs)
sorted.mean <- sorted.prob <- array(0, dim=dim(mean.data))
for(i in 1:nrow(mean.data)){
sorted.data[i,] <- mean.data[i,order(mean.data[i,])]
sorted.prob[i,] <- prob.data[i,order(mean.data[i,])]
}

Thanks,
Vumani

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] i suspect that there a memory leak in "vmmin"?

2006-07-05 Thread Vumani Dlamini
Dear listers,
Am currently using MCMC approaches to estimate some parameters of my model. 
One parameter has to be updated using a tuned gamma distribution. So at each 
iteration I estimate the mean and variance of the density of the gamma 
approximation using "vmmin" (i also supply the gradient argument). For 
moderate replications the procedure works, but if I increase them R crashes. 
If instead of the tuned gamma density i use the adaptive rejection sampling 
procedure by Gilks and Wild (downloaded from their website) the procedure 
returns the results for any number of replications, thus I suspected that 
there was a memory leak in "vmmin". I am not an expert in "C"  and am only a 
windows user. Have tried some of the debugging tools available to us windows 
users: gdb, mpatrol, duma without success. Am not sure whether this is a 
bug.

Version 2.3.1 (2006-06-01)
Windows XP

Regards, Vumani



Rgui.exe caused an Access Violation at location 100dec2f in module R.dll 
Reading from location 3ff7c27d.

Registers:
eax=63ac ebx=01e773a0 ecx=3ff7c27a edx=0002 esi=01e254b4 
edi=0002
eip=100dec2f esp=00e0ecb0 ebp=00e0ed78 iopl=0 nv up ei pl nz na pe 
nc
cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs= 
efl=0202

Call stack:
100DEC2F  R.dll:100DEC2F  SET_TAG
100E0527  R.dll:100E0527  Rf_allocVector
100E0D37  R.dll:100E0D37  R_alloc
100F2ACA  R.dll:100F2ACA  vmmin
023F5E96  gem.dll:023F5E96  weibullMH
10088C33  R.dll:10088C33  do_dotcall
100B8827  R.dll:100B8827  Rf_eval
100BA4D2  R.dll:100BA4D2  do_set
100B86CB  R.dll:100B86CB  Rf_eval
100BA5D5  R.dll:100BA5D5  do_begin
100B86CB  R.dll:100B86CB  Rf_eval
100BB8EB  R.dll:100BB8EB  Rf_applyClosure
100B85F8  R.dll:100B85F8  Rf_eval
100BA4D2  R.dll:100BA4D2  do_set
100B86CB  R.dll:100B86CB  Rf_eval
100DB51C  R.dll:100DB51C  Rf_ReplIteration
100DBAA6  R.dll:100DBAA6  run_Rmainloop
004013CF  Rgui.exe:004013CF
00401316  Rgui.exe:00401316
00401518  Rgui.exe:00401518
00401236  Rgui.exe:00401236
00401288  Rgui.exe:00401288
7C816D4F  kernel32.dll:7C816D4F  RegisterWaitForInputIdle

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] using "rbinom" in C code gives me erroneous results... random variable is not random (always zero)...

2006-06-29 Thread Vumani Dlamini
Dear Listers,
I am trying to use "rbinom" in my C code, but i always get zeros as output no 
matter the probability. Am not sure what I am doing wrong because the function 
has worked before. Attached in an example. Noticed that "rbinom" expects 'n' to 
be REAL.
Regards, Vumani
 
R  2.3.1 (2006-06-01)
Windows XP
Gcc
/* Called this file binom.c and then ran rcmd shlib on it */#include 
#include #include #include SEXP binomial(SEXP 
r, SEXP n, SEXP p){ int i; SEXP out; PROTECT(out = 
allocVector(REALSXP,INTEGER(r)[0]));  for(i = 0; i < INTEGER(r)[0]; ++i){  
REAL(out)[i] = rbinom(REAL(n)[0],REAL(p)[0]); } Rprintf("%d   %f   
%f\n",INTEGER(r)[0],REAL(n)[0],REAL(p)[0]); UNPROTECT(1); return(out);}
 
### used theses line in R
dyn.load("binom.dll").Call("binomial",as.integer(10),as.double(1),as.double(0.4))dyn.unload("binom.dll")
_
Try Live.com - your fast, personalized homepage with all the things you care 
about in one place.
http://www.live.com/getstarted
[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] fitting a distribution using glm

2006-03-08 Thread Vumani Dlamini
it is easy to fit a distribution using fitdistr

poisdata <- rpois(n = 100, lambda = 2)
poismle <- fitdistr(poisdata, "Poisson")
poismle

but i would like to know whether its possible to get an identical result 
using glm. I use

poistab <- data.frame(table(poisdata))
colnames(poistab) <- c("width","freq");
poistab[,"width"] <- as.numeric(poistab[,"width"])
glm(freq ~ 1-width, family = poisson, data = poistab)

but the results are always different.
cheers, vumani

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] R function use in C returning a list

2006-02-23 Thread Vumani Dlamini
Dear R users,
Is it possible to use an R function accepting several arguments and 
returning a list in C code. I notice that in all examples only one variable 
is returned.
Here is the C part I feel is giving the problems,

SEXP R_fcall, ans;
PROTECT(R_fcall = lang2(likelihood, R_NilValue));
++nProtected;
defineVar(install("PAR"), PAR, env);
defineVar(install("DATA"), oldData, env);
defineVar(install("N"), N, env);
PROTECT(ans =  eval(R_fcall, env));

oldData is a matrix which i set using

SEXP dim;
PROTECT(dim = NEW_INTEGER(2));
++nProtected;
INTEGER_DATA(dim)[0] = n;
INTEGER_DATA(dim)[1] = 2;
setAttrib(oldData, R_DimSymbol, dim);

if i return both function and data they are ok, but its evaluating the 
function and returning the list or even a single number which is a problem.
Thanks again, Vumani

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] RCMD SHILB uses g++ instead of gcc

2006-02-17 Thread Vumani Dlamini
I am using RCMD SHLIB to make a dll from the convolve2.c code presented with 
R-exts. After an e-mail from Prof Ripley, I noticed that SHLIB is using a 
C++ compiler instead of a C compiler for the code.

Have searched the R-site and the internet for answers and noticed that it is 
possible to change the "makeconf" and "makefile" files to correct this. But 
these files are not present in my system. I downloaded 
"R-2.2.1pat-win32.exe" and installed the traditional windows way.

Thanks for your responses.

Full_Name: Vumani Dlamini
Version: 2.2.1 Patched
OS: Microsoft Windows XP Professional





>From: Prof Brian Ripley <[EMAIL PROTECTED]>
>To: Vumani Dlamini <[EMAIL PROTECTED]>
>CC: r-help@stat.math.ethz.ch
>Subject: Re: [R] symbol decoration and .Call
>Date: Thu, 16 Feb 2006 13:12:25 + (GMT)
>
>1) Please read the posting guide and use the appropriate list, not R-help.
>
>2) Please tell us exactly what you did, including your OS, R version and so 
>on as the guide asks.  Looks to me like you used a C++ compiler to compile 
>C.
>
>On Thu, 16 Feb 2006, Vumani Dlamini wrote:
>
>>Dear R-users,
>>I am a novice user of .Call and am trying to use the C code in R-Ext to
>>kickstart my learning process. All the code compiles but when I try to use
>>.Call it gives the error (using "out.c" as an example),
>>
>>Error in .Call("out", x, y) : C entry point "out" not in load table
>>
>>when i use PEDUMP to check whether the symbol is loaded I find that it is
>>loaded as "_Z3outP7SEXPRECS0_" and when I use this instead of "out" the
>>program work.
>>
>>How can I remove the decoration so that only "out" is loaded?
>>
>>Thanks, Vumani
>>
>>__
>>R-help@stat.math.ethz.ch mailing list
>>https://stat.ethz.ch/mailman/listinfo/r-help
>>PLEASE do read the posting guide! 
>>http://www.R-project.org/posting-guide.html
>>
>
>--
>Brian D. Ripley,  [EMAIL PROTECTED]
>Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
>University of Oxford, Tel:  +44 1865 272861 (self)
>1 South Parks Road, +44 1865 272866 (PA)
>Oxford OX1 3TG, UKFax:  +44 1865 272595

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] symbol decoration and .Call

2006-02-16 Thread Vumani Dlamini
Dear R-users,
I am a novice user of .Call and am trying to use the C code in R-Ext to 
kickstart my learning process. All the code compiles but when I try to use 
.Call it gives the error (using "out.c" as an example),

Error in .Call("out", x, y) : C entry point "out" not in load table

when i use PEDUMP to check whether the symbol is loaded I find that it is 
loaded as "_Z3outP7SEXPRECS0_" and when I use this instead of "out" the 
program work.

How can I remove the decoration so that only "out" is loaded?

Thanks, Vumani

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] finding roots of a polynomial

2005-10-16 Thread Vumani Dlamini
Dear listers,
I am trying to find the root of a polynomial of the form,
   a+bx+cx^2+dx^3+ex^5+...=0
where a,b,c,d,e are known.
I have looked at "quadprog" without any success.
Regards, Vumani

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] drawing a network digraph

2005-08-04 Thread Vumani Dlamini
Dear R users,
I have a matrix with 2 columns with the variables: "daughter index", "mother 
index". I would like to draw a network digraph using this data, where each 
daughter is connected to a mother and between the connections inlcude a 
circle with the information on the indices ("daughter index", "mother 
index"): i.e. something similar to graphs produced by graphviz.
I am clueless. I have looked at the libraries SEM and SNA but it looks like 
they can't help my cause.
Hope you help.
Vumani

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] "\n" in legend using substitute and as.expression

2005-06-01 Thread Vumani Dlamini

Dear R users,
Is it possible to force a hard return in an expression. I tried including 
one for a legend using an expression and it didn't work. Here is my code,

legend(12, 0.10, c("Fitted density",
   as.expression(substitute(paste("Weibull (", alpha==shapeU," , ", 
beta==scaleU,") Mean = ",meanU," days"),

list(shapeU = round(mle.r$estimate[1],3),
scaleU = round(mle.r$estimate[2],3),
meanU = round(mle.r$estimate[3),4 ),
   lty=c(1,1),col=c(1,2),lwd=c(1,1),merge = TRUE)

(Windows XP + R2.10 user)

Thanks,
Vumani

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] including R function in C program

2005-05-10 Thread Vumani Dlamini
Is it possoble to include an R function in a C program? I would like to use 
"rmultz" from the "combinat" library to sample a multinomial vector within 
my C program, and have no clue how this can be done.
Thanks.
Vumani

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] DLL problem when using gcc+gsl

2005-04-27 Thread Vumani Dlamini
Dear list;
This might sound a bit naive, but then I am new to linking C DLL's to R.
I have built a DLL using GCC and am able to load the DLL in R 
(is.loaded("contents")==TRUE). When I include it in my function it returns 
NaN for all the variables. My R function is,

dyn.load("c:/data/tempdll.dll")
is.loaded("contents")#returns TRUE
#
contents <- function(new.cases){
   cases <- rep(0, length(new.cases))
   case.times <- rep(0, length(new.cases))
   temp <- .C("contents",
   as.integer(cases),
   as.double(case.times))
}
and the header of my C function is
#ifndef _DLL_H_
#define _DLL_H_
#if BUILDING_DLL
# define DLLIMPORT __declspec (dllexport)
#else /* Not BUILDING_DLL */
# define DLLIMPORT __declspec (dllimport)
#endif /* Not BUILDING_DLL */
DLLIMPORT void contents (int *cases,
double *case_times);
#endif /* _DLL_H_ */
and my C function is.
#include 
#include 
#include 
#include "dll.h"
#include 
#include 
void contents(int *cases,
 double *case_times)
{
   gsl_rng * r;
   gsl_rng_env_setup();
   r = gsl_rng_alloc (gsl_rng_default);
   int i;
for(i = 0; i < 1000; i++)
{
   cases[i] = gsl_ran_negative_binomial (r, 0.10/2.10, 0.10);
   case_times[i] = gsl_ran_weibull (r, 9, 5);
}
   gsl_rng_free (r);
}
I am clueless as to where it all goes wrong, as if I make the program an 
executable it works.

Thanks again.
Vumani
__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] sampling from a mixture distribution

2005-03-23 Thread Vumani Dlamini
Dear R users,
I would like to sample from a mixture distribution p1*f(x1)+p2*f(x2). I 
usually sample variates from both distributions and weight them with their 
respective probabilities, but someone told me that was wrong. What is the 
correct way?
Vumani

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] counting number of objects in a list

2004-06-08 Thread Vumani Dlamini
Dear R-users;
I am interested in getting the number of objects in a list, and have thus 
far been unsuccessful. Can you please help.

Thank you.
Vumani
__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] manipulating elements of a vector

2004-05-27 Thread Vumani Dlamini
Dear R users;
I would like to convert a series of vectors to matrices in the following 
way;
(2,1,1) to a matrix
1 0 0
1 0 0
0 1 0
0 0 1

The idea is that the column sum of the matrix should be equal to the 
elements of the vector.

Thanks.
Vumani
__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] subsetting based on vector

2004-03-25 Thread Vumani Dlamini
Thanks man. It did the trick.

Vumani


From: Winfried Theis <[EMAIL PROTECTED]>
To: Vumani Dlamini <[EMAIL PROTECTED]>
CC: [EMAIL PROTECTED]
Subject: Re: [R] subsetting based on vector
Date: Thu, 25 Mar 2004 16:16:58 +0100
Hi!

Well, you could try a subsetting rule like " year %in% yearsconsidered
".
Hope this helps,

Winfried
On Thu, 2004-03-25 at 14:33, Vumani Dlamini wrote:
> Dear R users;
>
> I am trying to write a small program which reads in a data set, and 
selects
> observations from certain years before the analysis. I have a problem
> including the selection criteria in the header of the program.
>
> Here is the problem;
>
> dataFIT<-function(MODEL, MARGINS, yearConsidered){
> library(foreign
> CovPaper<-read.spss("C:/Data/data.sav")
> NewData <- list(CovPaper$"YEAR"[CovPaper$"YEAR" == yearConsidered],
>   CovPaper$"YEAR"[CovPaper$"SEX" == 
yearConsidered],
>    and so on #
>#fit model to data #
> }
>
> When I use one year there is no problem, but I would like some data sets 
to
> span over years and I am not sure how to do this without having to 
change
> the body of my fitting program.
>
> I tried searching the R-list but to no avail.
>
> Thanking you in advance.
>
>
> Vumani
>
> _
> Hotmail en Messenger on the move
> http://www.msn.nl/communicatie/smsdiensten/hotmailsmsv2/
>
> __
> [EMAIL PROTECTED] mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! 
http://www.R-project.org/posting-guide.html
--
-
Dr. Dipl.-Math. Winfried Theis, SFB 475, Projekt C5,
Universität Dortmund, 44221 Dortmund
e-mail: [EMAIL PROTECTED]
Tel.: +49/231/755-5903 FAX: +49/231/755-4387

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] subsetting based on vector

2004-03-25 Thread Vumani Dlamini
Dear R users;

I am trying to write a small program which reads in a data set, and selects 
observations from certain years before the analysis. I have a problem 
including the selection criteria in the header of the program.

Here is the problem;

dataFIT<-function(MODEL, MARGINS, yearConsidered){
   library(foreign
   CovPaper<-read.spss("C:/Data/data.sav")
   NewData <- list(CovPaper$"YEAR"[CovPaper$"YEAR" == yearConsidered],
 CovPaper$"YEAR"[CovPaper$"SEX" == yearConsidered],
  and so on #
  #fit model to data #
}
When I use one year there is no problem, but I would like some data sets to 
span over years and I am not sure how to do this without having to change 
the body of my fitting program.

I tried searching the R-list but to no avail.

Thanking you in advance.

Vumani

_
Hotmail en Messenger on the move 
http://www.msn.nl/communicatie/smsdiensten/hotmailsmsv2/

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] (no subject)

2003-08-20 Thread Vumani Dlamini
Dear R users,

I am trying to convert a dataset from one format to several rectangular 
datasets. A consultant helped design the data entry program for our survey 
using Delphi/Pascal and for each household the information is stored in a 
file called "EA-HM-HH.TXT" where EA is the enumeration area number, HM is 
the homestead number and HH is the household number. Within this file the 
data is stored as follows,

## file="5677-001-001.TXT" ##
EAnumber=5677
HMnumber=001
HHnumber=001
# Demographics section
Dserial=01   #first person in household
Dage=56
Dsex=1
Dserial=02   #second person in household
Dage=44
Dsex=2
Dserial=03   #second person in household
Dage=7
Dsex=2
# Agricultural inputs section
Amaize=200
Apumpkins=50
## end of file 
Note that in the demograpics section there may only be less than 3 or more 
people in some households. I would like to create a file for the 
demographics section which is as follows

EAnumber|HMnumber|HHnumber|Dserial|Dage|Dsex
5677 001 001 056 1
5677 001 001 044 2
5677 001 001 007 2
and for the agricultural inputs I would like to have,

EAnumber|HMnumber|HHnumber|Amaize|Apumpkins
5677 001 001 0200
5677 001 001 0050
There are several similar files where the EA number, HM number or HH number 
changes, thus I would also like to know whether it is possible to create a 
script where for all household there is only one dataset for demographics, 
and one for agricultural inputs.

Thanking you as always.

Vumani Dlamini

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


[R] query on converting survey data from one structure to another

2003-08-20 Thread Vumani Dlamini
Dear R users,

I am trying to convert a dataset from one format to several rectangular 
datasets. A consultant helped design the data entry program for our survey 
using Delphi/Pascal and for each household the information is stored in a 
file called "EA-HM-HH.TXT" where EA is the enumeration area number, HM is 
the homestead number and HH is the household number. Within this file the 
data is stored as follows,

## file="5677-001-001.TXT" ##
EAnumber=5677
HMnumber=001
HHnumber=001
# Demographics section
Dserial=01   #first person in household
Dage=56
Dsex=1
Dserial=02   #second person in household
Dage=44
Dsex=2
Dserial=03   #second person in household
Dage=7
Dsex=2
# Agricultural inputs section
Amaize=200
Apumpkins=50
## end of file 
Note that in the demograpics section there may only be less than 3 or more 
people in some households. I would like to create a file for the 
demographics section which is as follows

EAnumber|HMnumber|HHnumber|Dserial|Dage|Dsex
5677 001 001 056 1
5677 001 001 044 2
5677 001 001 007 2
and for the agricultural inputs I would like to have,

EAnumber|HMnumber|HHnumber|Amaize|Apumpkins
5677 001 001 0200
5677 001 001 0050
There are several similar files where the EA number, HM number or HH number 
changes, thus I would also like to know whether it is possible to create a 
script where for all household there is only one dataset for demographics, 
and one for agricultural inputs.

Thanking you as always.

Vumani Dlamini

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


[R] Hmisc multiple imputation functions

2003-06-16 Thread Vumani Dlamini
Dear all;

I am trying to use HMISC imputation function to perform multiple imputations 
on my data and I keep on getting errors for the code given in the help 
files.

When using "aregImpute" the error is;

f <- aregImpute(~y + x1 + x2 + x3, n.impute=100)
Loading required package: acepack
Iteration:1 Error in .Fortran("wclosepw", as.double(w), as.double(x), 
as.double(runif(lw)),  :
   C/Fortran function name not in load table

When I use "transcan" it is;

f  <- transcan(~y + x1 + x2, n.impute=10, shrink=FALSE)
Error in transcan(~y + x1 + x2, n.impute = 10, shrink = FALSE) :
   Must specify data= when using R
I am not sure what I am missing.

Vumani

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


[R] memory problems in NLME

2003-03-30 Thread Vumani Dlamini
Dear R-Users

I am trying to fit a random coeficient model with about 30 covariates with a 
random intercept and one random slope. The data set has 65000 observations, 
and whenever I use LME I get the message that all memory has been used.

I was wondering whether there is a more efficient way fo fitting the model.

OS:  Windows 2000
R version:   R 1.6.2
Memory:  128Mb
Free HD: <>11Gb
Looking forward to you help as always.

Vumani Dlamini

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


[R] random error and grouping variable correlated

2003-03-27 Thread Vumani Dlamini
Dear R-users:

Is it possible to fit linear mixed models using LME when the random error is 
correlated with one of the covariates in the model?

Thanks.

Vumani Dlamini

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


[R] Simple NLME problem (I hope)

2003-03-26 Thread Vumani Dlamini
Dear R-Users:

I would like to fit a multilevel model using LME such that the parameters 
after fitting the multilevel in two separate groups and when I use the 
complete data (with interactions between the grouping variable and the other 
variables) set are comparable (or the same).

The problem I am having currently is that I am not sure whether it is 
possible to let the random error term to vary by group such that the models 
are comparable. At present only one random error term is estimate and this 
"sort of" distorts the parameter estimates for the fixed and other random 
effects.

Looking forward to your help.



Vumani Dlamini

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


[R] expression for simple EM

2003-02-23 Thread Vumani Dlamini
Dear R users,

I know this is the wrong forum for such a question but I need help.

I would like to write down the likelihood expression for a simple EM 
problem. I have one categorical covariate with 5 levels and a missing count 
which can fall in any of the categories. I know the solution to the problem 
but can't seem to get the likelihood expression correct (if it is possible).

Thanks.

Vumani Dlamini, Student
Faculty of Health Sciences
University of Natal
__
[EMAIL PROTECTED] mailing list
http://www.stat.math.ethz.ch/mailman/listinfo/r-help


[R] something wrong when using pspline in clogit?

2003-01-22 Thread Vumani Dlamini


Dear R users:

I am not entirely convinced that clogit gives me the correct result when I 
use pspline() and maybe you could help correct me here.

When I add a constant to my covariate I expect only the intercept to change, 
but not the coefficients. This is true (in clogit) when I assume a linear in 
the logit model, but the same does not happen when I use pspline().

If I did something similar to what "na.gam.replace" in S+ does, the pspline 
coefficients are the same, leading me to believe that "na.gam.replace" is 
doing the right thing (I may be wrong).
The strange thing here is that even the intercepts are the same. Lastly, 
these coefficients are the same as using clogit before adding the constant, 
but the intercept are different.

I have attached my code for all this, maybe I messed it somewhere.


Vumani

##
xvar<-rnorm(100,0,1)
data.mult<-rbinom(100,size=3,prob=(exp(0.5+0.4*xvar)/(1+exp(0.5+0.4*xvar
library(Nnet)
mult.fit<-multinom(data.mult~xvar)
coef(mult.fit)
library(survival)
choice<-c(ifelse(data.mult==0,1,0),ifelse(data.mult==1,1,0),ifelse(data.mult==2,1,0),ifelse(data.mult==3,1,0))
temp<-list(time=2-choice,
   status=choice,
   
intercept1=c(rep(0,length(data.mult)),rep(1,length(data.mult)),rep(0,length(data.mult)),rep(0,length(data.mult))),
   
intercept2=c(rep(0,length(data.mult)),rep(0,length(data.mult)),rep(1,length(data.mult)),rep(0,length(data.mult))),
   
intercept3=c(rep(0,length(data.mult)),rep(0,length(data.mult)),rep(0,length(data.mult)),rep(1,length(data.mult))),
   
xvar1=c(rep(0,length(data.mult)),rep(1,length(data.mult)),rep(0,length(data.mult)),rep(0,length(data.mult)))*rep(xvar,4),
   
xvar2=c(rep(0,length(data.mult)),rep(0,length(data.mult)),rep(1,length(data.mult)),rep(0,length(data.mult)))*rep(xvar,4),
   
xvar3=c(rep(0,length(data.mult)),rep(0,length(data.mult)),rep(0,length(data.mult)),rep(1,length(data.mult)))*rep(xvar,4),
   stratum=rep(1:length(data.mult),4))
# Used to check whether my data matrix is setup correctly
# This fits a category one baseline category logit model
# Compare with multinom
totalmodel<-clogit(status~intercept1+intercept2+intercept3+xvar1+xvar2+xvar3+strata(stratum),method="exact",temp)
coef(totalmodel)
# Use smooth term, "pspline"
totalmodel<-clogit(status~intercept1+intercept2+intercept3+pspline(xvar1)+pspline(xvar2)+pspline(xvar3)+strata(stratum),method="exact",temp)
coef(totalmodel)
# Collect indices where variable is not equal to zero
indices<-list(var1=NULL,var2=NULL,var3=NULL)
indices$var1<-temp$xvar1==0
indices$var2<-temp$xvar2==0
indices$var3<-temp$xvar3==0
# Add 10 to covariate
temp$xvar1[!indices$var1]<-xvar+10
temp$xvar2[!indices$var2]<-xvar+10
temp$xvar3[!indices$var3]<-xvar+10
# First fit linear-in-the-logit model, to check what happens to coefficients
totalmodel<-clogit(status~intercept1+intercept2+intercept3+xvar1+xvar2+xvar3+strata(stratum),method="exact",temp)
coef(totalmodel)
# Fit a smooth model, and compare with smooth model above
totalmodel<-clogit(status~intercept1+intercept2+intercept3+pspline(xvar1)+pspline(xvar2)+pspline(xvar3)+strata(stratum),method="exact",temp)
coef(totalmodel)
# Doing something similar to what na.gam.replace() in S+ does
temp$xvar1[indices$var1]<-mean(xvar+10)
temp$xvar2[indices$var2]<-mean(xvar+10)
temp$xvar3[indices$var3]<-mean(xvar+10)
# Fit spline model
totalmodel<-clogit(status~intercept1+intercept2+intercept3+pspline(xvar1)+pspline(xvar2)+pspline(xvar3)+strata(stratum),method="exact",temp)
coef(totalmodel)
# Remove 10 and substitute with mean
# Covariate are like in the beginning
temp$xvar1[!indices$var1]<-xvar
temp$xvar2[!indices$var2]<-xvar
temp$xvar3[!indices$var3]<-xvar
# Doing something like na.gam.replace()
temp$xvar1[indices$var1]<-mean(xvar)
temp$xvar2[indices$var2]<-mean(xvar)
temp$xvar3[indices$var3]<-mean(xvar)
totalmodel<-clogit(status~intercept1+intercept2+intercept3+pspline(xvar1)+pspline(xvar2)+pspline(xvar3)+strata(stratum),method="exact",temp)
coef(totalmodel)







From: [EMAIL PROTECTED]
To: Vumani Dlamini <[EMAIL PROTECTED]>
CC: [EMAIL PROTECTED]
Subject: Re: [R] R analogue
Date: Mon, 20 Jan 2003 13:17:02 + (GMT)

On Mon, 20 Jan 2003, Vumani Dlamini wrote:

> Is there any R analogue for the S+ function "na.gam.replace".

No, for it is tailored for use by S's gam.

Some of the things it does are positively undesirable!  It uses mean
imputation for continuous variables, but for factors it makes NA into
another level, which silently assumes that all missing values are similar
and that they are going to occur with sufficient frequency in the
training data (and they may not occur at all).

> I would like
> to make an interaction of a categorical and smooth continuous covariate.

[R] R analogue

2003-01-20 Thread Vumani Dlamini

Dear R users:

Is there any R analogue for the S+ function "na.gam.replace". I would like 
to make an interaction of a categorical and smooth continuous covariate.

Thanks.



Vumani Dlamini
Central Statistical Office
Swaziland

__
[EMAIL PROTECTED] mailing list
http://www.stat.math.ethz.ch/mailman/listinfo/r-help


[R] Re: Universal legend in plot

2003-01-17 Thread Vumani Dlamini
Dear R-users:

I asked a question on how I can have a universal legend in a plot and 
received the following result. I tried using "layout" but I can't seem to 
work on the "empty" plot (where I have to have the legend). I tried "oma" 
but I couldn't improve the quality of the plot, and that I didn't know how 
to specify all the line types using the keyboard, infact it is line type 4 
(I had _._ and it didn't look nice).

#
I am trying to create a graph with 6 panels, but would like to have a 
universal legend as each panel merely denotes a separate stratum. The legend 
has to be at the bottom.

I use "par(mfrow=c(2,3))" to get the panels, but am not sure how to put the 
legend below the whole graph.

Thanking you as always


J.R. Lockwood

I don't think you can do this without

layout()

which you can use to create a separate graphical area within the plot
region, where you can put the legend.

i could be wrong though

Peter Dalgaard

You need to look at mtext(,outer=TRUE), plus par(oma=) to make
room for the text in the outer margins.

Try layout() for finer adjustments (and some drawbacks).
See ?layout how to set up a 7th figure (legend) of full with below the 
desired six other figures.

Uwe Ligges

__
[EMAIL PROTECTED] mailing list
http://www.stat.math.ethz.ch/mailman/listinfo/r-help


[R] Universal legend for graph...

2003-01-14 Thread Vumani Dlamini

Dear R-Users:

I am trying to create a graph with 6 panels, but would like to have a 
universal legend as each panel merely denotes a separate stratum. The legend 
has to be at the bottom.

I use "par(mfrow=c(2,3))" to get the panels, but am not sure how to put the 
legend below the whole graph.

Thanking you as always.



Vumani Dlamini
Swaziland




_
Add photos to your e-mail with MSN 8. Get 2 months FREE*.

__
[EMAIL PROTECTED] mailing list
http://www.stat.math.ethz.ch/mailman/listinfo/r-help


[R] negatively correlated binary data

2003-01-08 Thread Vumani Dlamini

Dear R users:


Is there a way to create negatively correlated binary data in R. I have 
looked at bindata, but it seems it only works with positively correlated 
data.


Thanks.


Vumani Dlamini
Swaziland

__
[EMAIL PROTECTED] mailing list
http://www.stat.math.ethz.ch/mailman/listinfo/r-help