1 Dec 01:01 2005

### [R] Row wise function call.

```I have another issue.i have a function which calculates the log2(col i
/col2) value, where i stands for columns 3,4,...etc.

iratio<-function(x){
for(n in 3:ncol(data)){
z<-log2(data[x,n]/data[x,2])
}
}

Where x- the row number of the data frame(data).

i want to store the ratios for each row in a object z,  which can be
accessed outside the function. How can i do this?

Thanks,
Vasu.

[[alternative HTML version deleted]]

______________________________________________
R-help <at> 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

```
1 Dec 02:14 2005

### Re: [R] Solving Systems of Non-linear equations

```Just one addition to this.  I noticed that its not really true that
the output can be used in R verbatim since the C output uses
pow instead of ^; however, if one replaces the "code c" statement
with the statement "list export" then it is valid R.  That is the input
to mathomatic should be:

mean = a/(a+b)
variance = (a*b)/(((a+b)^2) * (a+b+1))

eliminate b
a
simplify
list export

eliminate a
b
simplify
list export

On 11/30/05, Gabor Grothendieck <ggrothendieck <at> gmail.com> wrote:
> Sorry I seemed to have messed up the copying and pasting.
> Here it is again.
>
> ---
>
> Go to http://mathomatic.orgserve.de/math/ and install mathomatic
> (its free) or just connect to the online server and do this.
>
> The C output, i.e the result of the two code c commands,
> can be used verbatim in R.
```

1 Dec 02:41 2005

### Re: [R] fixed, random effects with variable weights

```	  I don't have STATA and your example is not sufficiently complete for
me to replicate anything.  However, my approach to that kind of thing is
to try to find the absolute simplest possible example I can think and
work with that.  I have on occasion programmed such simple examples in
Excel;  if I get the same answers from Excel and R, I have reasonable
confidence that I know that R (or STATA) is doing.

Beyond that, you have a great advantage with R in that the source
code is available:  To see the R source, type the name of the function
at a command prompt.  If I do that with "lme", I get the following:

> lme
function (fixed, data = sys.frame(sys.parent()), random, correlation =
NULL,
weights = NULL, subset, method = c("REML", "ML"), na.action = na.fail,
control = list(), contrasts = NULL)
UseMethod("lme")

This is not too helpful by itself.  To get further, I use "methods":

> methods("lme")
[1] lme.formula      lme.groupedData* lme.lmList

Your "fixed" argument appears to have class "formula".  In that case,
"lme.formula" is the function you want.  Typing this at a command prompt
gives you the code.  You can then copy that into a script file, print it
out, and walk through it line by line to make sure you understand what
it does.  A walk-through like this can be facilitated by using "degug",
which you can invoke as follows:

```

1 Dec 04:07 2005

### [R] Error in structural equation model - "The model has negative degrees of freedom"

```Hi

I am running a structural equation model with R using the sem command; am
getting the following error:

"Error in sem.default : The model has negative degrees of freedom = -4"

My model is as follows:

s_model = specify.model()
x1->m1, b1,NA
x2->m1, b2,NA
x3->m2, b3,NA
x4->m2, b4,NA
x5->m2, b5,NA
x6->m2, b6,NA
m1->y, a1,NA
m2->y, a2,NA
m1<->m1, v1,NA
m2<->m2, v2,NA
y<->y, v3,NA

x1-x6 are observed independent variables, m1 and m2 are the latent variables
and y is the observed dependent variable. I use the raw.moments command for
calculating the covariance matrix, based on a data with 147 observations.

The command that I use is as follows:

s = sem(s_model,S=R,obs.variables=colnames(R),
fixed.x=c('x1','x2','x3','x4','x5','x6'), raw=TRUE)
```

1 Dec 04:17 2005

### Re: [R] Row wise function call.

```Vasundhara Akkineni wrote:
> I have another issue.i have a function which calculates the log2(col i
> /col2) value, where i stands for columns 3,4,...etc.
>
>
> iratio<-function(x){
> for(n in 3:ncol(data)){
> z<-log2(data[x,n]/data[x,2])
> }
> }
>
> Where x- the row number of the data frame(data).
>
> i want to store the ratios for each row in a object z,  which can be
> accessed outside the function. How can i do this?

Just return the result at the end of the function.  Since you want to
return log-ratios for many pairs, I would suggest to stick them in a new
data frame, or since they results are all of the same data type, a

iratio <- function(rows) {
# Create (pre-allocate) empty matrix poulated with NAs
z <- matrix(NA, nrow=length(x), ncol=ncol(data)-3+1);

for(col in 3:ncol(data)) {
z[,col-3+1] <- log2(data[rows,col] / data[rows,2])
}

```

1 Dec 05:11 2005

### [R] Strange Estimates from lmer and glmmPQL

```I'm trying to fit a generalized mixed effects model to a data set where
each subject has paired categorical responses y (so I'm trying to use a
binomial logit link). There are about 183 observations and one
explanatory factor x. I'm trying to fit something like:

(lmer(y~x+(1|subject)))

I also tried fitting the same type of model using glmmPQL from MASS. In
both cases, I get a t-statistic that is huge (in the thousands) and a
tiny p-value. (Just for comparison, if I use lrm ignoring the clustering
I get a t-statistic around 3 or so and what appears to be a reasonable
estimated coefficient which is very close to the estimated coefficient
using just one observation from each subject.

Most of the subjects have two responses and in almost all cases the
responses are identical although the explantory factor values are not
always identical for each subject.

If I use geeglm from geepack, I get reasonable estimates close to the
naive model results.

I also tried using the SAS glimmix macro to fit a generalized mixed
model and the routine does not converge.

Why does geeglm appear to work but not lmer and glmmPQL? Is this likely
to be due to my particular data set?

Rick B.

______________________________________________
```

1 Dec 05:21 2005

### Re: [R] Row wise function call.

```Thanks, Peter and Henrik.

Vasu.

On 11/30/05, Henrik Bengtsson <hb <at> maths.lth.se> wrote:
>
> Vasundhara Akkineni wrote:
> > I have another issue.i have a function which calculates the log2(col i
> > /col2) value, where i stands for columns 3,4,...etc.
> >
> >
> > iratio<-function(x){
> > for(n in 3:ncol(data)){
> > z<-log2(data[x,n]/data[x,2])
> > }
> > }
> >
> > Where x- the row number of the data frame(data).
> >
> > i want to store the ratios for each row in a object z,  which can be
> > accessed outside the function. How can i do this?
>
> Just return the result at the end of the function.  Since you want to
> return log-ratios for many pairs, I would suggest to stick them in a new
> data frame, or since they results are all of the same data type, a
> matrix instead. Example:
>
> iratio <- function(rows) {
>   # Create (pre-allocate) empty matrix poulated with NAs
```

1 Dec 06:39 2005

### [R] values in between

```Hey there

I have two vectors:

y<- c(0.4,  0.0,  0.2, -0.2, -0.6, 0.2, 0.0, 0.0, 0.4, 0.4, 0.2)

In the vector y, I want to access (in the order given) all of the values in
between each of the specific values of given.

I understand subsetting with y[i], but how do I get to ssomewhere in
between -0.6 and 0.2?

Thanks
Eric Jennings
matheric <at> myuw.net

______________________________________________
R-help <at> 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

```
1 Dec 07:17 2005

### [R] What are the possible Probabilstic models in R

```   HI LIST
i am a new R user,    i am trying to make a model,which will give me output in probability,which will take
predictors and predictand  serie as input and and give me output in terms of probability(e.g below
normal,normal,above normal etc.).What is the package and what is the function for probability
model.What are the possible methods for fitting such type of model,and what is the package name for such
type of functions. i posted this question earliar ,but found no reply...so i am again posting the question.
anil

ANIL KUMAR( METEOROLOGIST GR -II)
LRF SECTION
NATIONAL CLIMATE CENTER
INDIA METEOROLOGICAL DEPARTMENT
SHIVIJI NAGAR
PUNE-411005 INDIA
MOBILE +919422023277
anilkumar <at> imdpune.gov.in

[[alternative HTML version deleted]]

______________________________________________
R-help <at> 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

```
1 Dec 08:20 2005

### Re: [R] library(its) problem

```On Wed, 30 Nov 2005, Erin Hodgess wrote:

> Dear R People:
>
> I wanted to use the package "its" this afternoon.
>
> I'm using R Version 2.2.0 for Windows.
>
> I was able to install the package, but ran into trouble at
> the "library" command.  Here is the output:
>
>> library(its)
> Hmisc library by Frank E Harrell Jr
>
> Type library(help='Hmisc'), ?Overview, or ?Hmisc.Overview')
> to see overall documentation.
>
> NOTE:Hmisc no longer redefines [.factor to drop unused levels when
> subsetting.  To get the old behavior of Hmisc type dropUnusedLevels().
>
> Attaching package: 'Hmisc'
>
>
>        The following object(s) are masked from package:stats :
>
>         ecdf
>
> Error in lazyLoadDBfetch(key, datafile, compressed, envhook) :
>        ReadItem: unknown type 241
```