Hi,
? I am very new to R. So, pardon my dumb question. I was trying to write my own
function to run a different model (perform an ordered logistic regression) using
the example in website http://pngu.mgh.harvard.edu/~purcell/plink/rfunc.shtml
But R returns a error `R Error in eval(expr, envir, enclos) : object 's'
not found' when I run it. What am I doing wrong here? Here's what I got
from the debug file.
# Input data
n <- 10
PHENO <- c( 1, 3, 2, 3, 1, 1, 1, 2, 1, 2 )
c <- c( 1, 1, 0, 0, 0, 0, 0, 1, 0, 0 )
COVAR <- matrix( c , nrow = n , byrow=T)
CLUSTER <- c( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 )
l <- 22
g <- c( 0, 1, 1, 0, 0, 0, 1, 0, 2, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1,
2, 0, 0, 0, 2, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 2, 0, 1, 1, 0, 1, 0, 0, 1, 0, 0,
0, 0, 0, 1, 0, 0, 1, 1, -1, -1, 1, 0, 0, 1, 1, -1, 1, 0, 1, 0, 0, 2, 0, 0, 0, 1,
0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 2, 0, 1, 0, 0, 1, 0, 1, 0, 1, 2, 0, 1, 1,
0, 1, 0, 2, 1, 0, 0, 0, 2, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, -1, -1, 0, 1, 0, 0, 0, 2, 0, 1, 0, 0, 0,
2, 0, 1, 1, 2, 0, 0, 1, 0, 1, -1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0,
0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 2, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0,
1, 1, 2, 0, 0, 0, 1, 1, 1, 0, 0 )
GENO <- matrix( g , nrow = n ,byrow=T)
GENO[GENO == -1 ] <- NA?
# Function
library(ordinal)
???? Rplink <- function(PHENO,GENO,CLUSTER,COVAR)
???? {
????? f1 <- function(s)
????? {
??????? m <- summary(clm(PHENO ~ s))
??????? r <- c(m$coef)
??????? c( length(r) , r )
????? }
???? apply( GENO , 2 , f1 )
???? }
Thanks,
?Debs
On Aug 30, 2011, at 6:49 PM, Debs Majumdar wrote:> Hi, > > > I am very new to R. So, pardon my dumb question. I was trying to > write my own function to run a different model (perform an ordered > logistic regression) using the example in website http://pngu.mgh.harvard.edu/~purcell/plink/rfunc.shtml > > But R returns a error `R Error in eval(expr, envir, enclos) : object > 's' not found' when I run it. What am I doing wrong here?How can we tell? You have not offered the code that you used to run it. The code you offered runs without difficulty (once I change the T's to TRUE's, that is).> Here's what I got from the debug file. > > # Input data > > n <- 10 > PHENO <- c( 1, 3, 2, 3, 1, 1, 1, 2, 1, 2 ) > c <- c( 1, 1, 0, 0, 0, 0, 0, 1, 0, 0 ) > COVAR <- matrix( c , nrow = n , byrow=T) > CLUSTER <- c( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ) > l <- 22 > g <- c( 0, 1, 1, 0, 0, 0, 1, 0, 2, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, > 0, 0, 1, 2, 0, 0, 0, 2, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 2, 0, 1, 1, > 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, -1, -1, 1, 0, 0, 1, 1, > -1, 1, 0, 1, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, > 0, 1, 2, 0, 1, 0, 0, 1, 0, 1, 0, 1, 2, 0, 1, 1, 0, 1, 0, 2, 1, 0, 0, > 0, 2, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, > 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, -1, -1, 0, 1, 0, 0, 0, 2, 0, 1, 0, 0, > 0, 2, 0, 1, 1, 2, 0, 0, 1, 0, 1, -1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, > 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 2, 0, 1, 1, > 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 2, 0, 0, 0, 1, 1, 1, 0, 0 ) > GENO <- matrix( g , nrow = n ,byrow=T) > GENO[GENO == -1 ] <- NA > > > # Function > > library(ordinal) > Rplink <- function(PHENO,GENO,CLUSTER,COVAR) > { > f1 <- function(s) > { > m <- summary(clm(PHENO ~ s)) > r <- c(m$coef) > c( length(r) , r ) > } > apply( GENO , 2 , f1 ) > } > > > Thanks, > > Debs > > > ______________________________________________ > R-help at r-project.org 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.David Winsemius, MD West Hartford, CT
Here's the plik code I ran:
plink --bfile olr_try1 --pheno p3.txt --pheno-name dnum --covar p3.txt
--covar-name a4 --missing-phenotype -9 --R olr2.R
The below function is contained in the olr2.R script.
The data which I input is contained in the binary file named olr_try1.
The response variable (PHENO) and the covariate (COVAR) is contained in the file
p3.txt.
I added the option --R-debug to get the output below.
?Thanks,
?Debs
----- Original Message -----
From: Debs Majumdar <debs_stata at yahoo.com>
To: "r-help at r-project.org" <r-help at r-project.org>
Cc:
Sent: Tuesday, August 30, 2011 3:49 PM
Subject: Error in evalauating a function
Hi,
? I am very new to R. So, pardon my dumb question. I was trying to write my own
function to run a different model (perform an ordered logistic regression) using
the example in website http://pngu.mgh.harvard.edu/~purcell/plink/rfunc.shtml
But R returns a error `R Error in eval(expr, envir, enclos) : object 's'
not found' when I run it. What am I doing wrong here? Here's what I got
from the debug file.
# Input data
n <- 10
PHENO <- c( 1, 3, 2, 3, 1, 1, 1, 2, 1, 2 )
c <- c( 1, 1, 0, 0, 0, 0, 0, 1, 0, 0 )
COVAR <- matrix( c , nrow = n , byrow=T)
CLUSTER <- c( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 )
l <- 22
g <- c( 0, 1, 1, 0, 0, 0, 1, 0, 2, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1,
2, 0, 0, 0, 2, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 2, 0, 1, 1, 0, 1, 0, 0, 1, 0, 0,
0, 0, 0, 1, 0, 0, 1, 1, -1, -1, 1, 0, 0, 1, 1, -1, 1, 0, 1, 0, 0, 2, 0, 0, 0, 1,
0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 2, 0, 1, 0, 0, 1, 0, 1, 0, 1, 2, 0, 1, 1,
0, 1, 0, 2, 1, 0, 0, 0, 2, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, -1, -1, 0, 1, 0, 0, 0, 2, 0, 1, 0, 0, 0,
2, 0, 1, 1, 2, 0, 0, 1, 0, 1, -1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0,
0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 2, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0,
1, 1, 2, 0, 0, 0, 1, 1, 1, 0, 0 )
GENO <- matrix( g , nrow = n ,byrow=T)
GENO[GENO == -1 ] <- NA?
# Function
library(ordinal)
???? Rplink <- function(PHENO,GENO,CLUSTER,COVAR)
???? {
????? f1 <- function(s)
????? {
??????? m <- summary(clm(PHENO ~ s))
??????? r <- c(m$coef)
??????? c( length(r) , r )
????? }
???? apply( GENO , 2 , f1 )
???? }
Thanks,
?Debs
Reasonably Related Threads
- Memory limits using read.table on Windows XP Pro
- [Fwd: Trend test and test for homogeneity of odd-ratios]
- R CMD check Error after R CMD build for R-2.11.0
- create multiple categorical variables in a data frame using a loop
- create multiple categorical variables in a data frame using a loop