[R] Want to create empty vectors inside a empty data frame

2008-12-27 Thread Moumita Das
Hi All,
I want to create empty vectors inside an empty data frame.The name of the
vectors has to come dynamically.

For example if record_mean is my empty data frame,and i have say 4
categories,the category names for record mean data frame has to
recmeanC1,recmeanC2,recmeanC3,recmeanC4,which will be dynamically created
and which will again be inserted in my data frame's as column values.Each of
these should be also vectors later.Because later i want to use the cbind
function.

I wanted to do this:--
record_mean<-cbind(recmeanC1,recmeanC2,recmeanC3,recmeanC4)


where:--
record_mean=>is my initially created empty data frame--[i
can create this]
recmeanC1,recmeanC2,recmeanC3,recmeanC4=>the names i generate
dynamically,according to the categories i have [Caregories is again
collection of items...[Able to do this]
recmeanC1=>this and others (like recmeanC2,recmeanC3,recmeanC4)=>should be
all vectors having the means of each records set item mean for a particular
category.[]

Say i have 2 categories:--
Category1 say has==>i1,i2(say i have 10 records,i.e i1,i2 pair values)
Category2 say has==>i3,i4(10 records )
recmeanC1=>means of each i1,i2 value per record for category 1 as vector (i
keep adding rows of means ,using rbind)
recmeanC2=>means of each i3,i4 value per record for category 1 as vector


what i did was:--
cat_record_mean_dfs<-data.frame(r_m=NULL)
#Preparing the number of categories mean storage dfs
for(catno in 1:catnam_dataset_data_size[1])
{
cat_record_mean<-paste("recmeanC",1:catno,sep="")
cat_mean_vector<-as.vector(cat_record_mean)
#str(cat_mean_vector)
print(cat_mean_vector)
#cat_record_mean_dfs<-c(cat_record_mean)
#print("each category mean storage place")
#print(cat_record_mean_dfs)

#cat_record_mean_dfs<-rbind(cat_record_mean_dfs,data.frame(cat_record_mean=NULL))
# adding rows to the empty data frame

}

Bottomline is ,can empty vectors be created inside an empty data frame?


-- 
Thanks
Moumita

[[alternative HTML version deleted]]

__
R-help@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.


[R] Calculating signicance value

2009-01-02 Thread Moumita Das
Hi friends,
If someone can find out some time to go through my problem would be really
grateful.

I have a dataset(dataset1) as shown below:--
   recmeanC1 recmeanC2   recmeanC3recmeanC4 i1 i2 i3 i4 i5 i6 i7
i8 i9 i10 i11
1 NA 1   1.00 1.80
NA  1 NA  1  1 NA  2  2  2  NA   2
2  2 2   1.00   1.83
2  2 NA NA NA  1  1  3  2   2   2
3  2 2   2.002.00
2  2 NA NA NA  2  2  2  2   2   2
4  2 2   2.00   1.33
2  2 NA NA NA  2  1  1  2   2   1
5  2NA1.002.002
NA NA NA NA  1  2  3  2   2   2
6  2 2 2.00 2.33
2  2 NA NA NA  2  1  3  3   3   2
7  1NA   1.00 2.331
NA NA NA NA  1  2  3  2   3   3

I want the results of correlation exactly as SPSS produces,with significance
value and N-size.
Here recmeanC1,C2,C3,C4 means the category means of the itemsCategory 1
has only item 1somean,same as item1,cat 2 has 2,cat 3 has 3,4,5,6 and cat 4
has 7,8,9,10,11,12.For all teh 7 record sets fetched i haves prepared the
dataset for correlation function.


My correlation function looks like this:
#Function for correlation
getCorrelationVal<-function(corr_dataset)
{

#Correlation of items and categories
if(corr_dataset=="NULL")
{
print("Correlation cannot be performed on this null dataset.")
}
else
{


BPcor<-cor(x=corr_dataset,y = NULL, use ="complete.obs",method =
c("pearson"))
return(list(matrix=BPcor)

}
}

Here corr_dataset is the data set i pass,as i have shown above.now how do i
find teh significance level for each correlation.valid N-size however i can
find.


this will generate correlation values like this:(i have not shown the
whole dataset)
recmeanC1   recmeanC2   recmeanC3 recmeanC4 i1  i2
recmeanC1  1.000  0.77020798  0.72965359 0.6352532  1.000
0.77020798
recmeanC2  0.7702080  1.  0.99016409 0.3057984  0.7702080
1.
recmeanC3  0.7296536  0.99016409  1. 0.3138384  0.7296536
0.99016409
recmeanC4  0.6352532  0.30579837  0.31383836 1.000  0.6352532
0.30579837
i1 1.000  0.77020798  0.72965359 0.6352532  1.000
0.77020798
i2 0.7702080  1.  0.99016409 0.3057984  0.7702080
1.
i3 0.7702080  1.  0.99016409 0.3057984  0.7702080
1.
i4 0.7702080  1.  0.99016409 0.3057984  0.7702080
1.
i5 0.7702080  1.  0.99016409 0.3057984  0.7702080
1.
i6 0.4970501  0.82035423  0.89229418 0.2960185  0.4970501
0.82035423
i7 0.3614032  0.69588900  0.76912242 0.2981885  0.3614032
0.69588900
i8 0.1756620  0.13529629  0.11867817 0.3254706  0.1756620
0.13529629
i9 0.5606119  0.43178777  0.37186590 0.3895178  0.5606119
0.43178777
i100.5380528  0.58589367  0.60919478 0.6058848  0.5380528
0.58589367
i110.4413674 -0.06798894 -0.07156563 0.7973308  0.4413674
-0.06798894



The problem is when i calcualte correlation without taking into
consideration the signification of every pair in the correlation values
shown above i just pass the above dataset .But how do i get significance of
e say:--
recmeanC1&recmeanC2 or say recmeanC1 & i1.
I can add this in my corr function shown above but:

#Finding out significance of the two items whose correlations are being
found
sig_value<-cor.test(corr_dataset)
and also return that :-
return(list(matrix=BPcor,sig=sig_value))

 For example recmeanC1 and i1 has to be passed here..as 2 separate
dataframes,shown below if i pass the dataset for (recmeanC1 & i1 ) as as
single datframe,cor.test() function doesn't accept it.Moreover cor()
function took care of what will be crossed with what and the correlation
produced.Now do i have to manually get possible pairs of the column names of
my dataset(shown above dataset 1),and also the data and then pass to
cor.test and calculate the significance.
Isn't there any easier way to do this,with minimum number of lines of
code.Because I am dealing with huge datasets.



-- 
Thanks In Advance :)
Moumita

[[alternative HTML version deleted]]

__
R-help@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.


[R] Warning message:In pt(q, df, lower.tail, log.p) : NaNs produced

2009-01-06 Thread Moumita Das
Hi friends,
Any idea why do i get this warning?And also why all computed p-values are
NaN.
Have shown below what i did in Windows r-console.:--
> df
  c1 c2
1  1 50
2 NA NA
3  4 NA
4  7  6
5 NA  7
6 10 10
> r<-cor(x=df,y=NULL,use="complete.obs",method=c("pearson"))
> r
   c1 c2
c1  1.000 -0.9148074
c2 -0.9148074  1.000
> cor.p.values<- function(r, n)
+ {
+   df <- n - 2
+   ESTIMATE <- c(cor = r)
+   PARAMETER <- c(df = df)
+   STATISTIC <- c(sqrt(df) * r / sqrt(1 - r^2))
+   p <- pt(STATISTIC, df)
+   return(2 * pmin(p, 1 - p))
+ }
> cor.p.values(r,2)
[1] NaN NaN NaN NaN
*Warning message:
In pt(q, df, lower.tail, log.p) : NaNs produced
*
Any help will be appreciated.. :)
-- 
Thanks
Moumita

[[alternative HTML version deleted]]

__
R-help@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.


[R] Can't i provide variables for the select clause of the subset function?

2009-01-06 Thread Moumita Das
Hi guys,
Have done something like this:---


   #Looping through each set of elements of the correlation
cross product combinations and collecting datatsets for those elements
for(corr_combs_counter in 1:1)
{

rowval_corr_combs<-corr_combs[corr_combs_counter,]
col1<-rowval_corr_combs[1] # i get the pairs firtst col
value like, i1
col2<-rowval_corr_combs[2] # i get the pairs second col
value like, i2

#getting each element dataset
col1val<-subset(item_category_table, select =",*col1*,")
col2val<-subset(item_category_table, select =",*col2*,")
col1val_size<-dim(col1val)
#col2val_size<-dim(col2val)
print(col1val)
print(col2val)
}
*Can't i use variable names as values of  "select =" ?if i hardcode the
columnames ,it works fine..*
I keep getting warnings:--
*Error in `[.data.frame`(x, r, vars, drop = drop) :
undefined columns selected
*
-- 
Thanks
Moumita

[[alternative HTML version deleted]]

__
R-help@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.


[R] Write and Load functions from an external file

2009-02-13 Thread Moumita Das
Hi All,

Would be grateful,if anyone can answer my queries.


I need to  share code. For example, if I am  working in C/C++, I would put
some function declarations in .h files that you would include. In PHP, I
would create files with the common functions in them and then "include()"
them. So far, I haven't been able to figure out what the standard practice
is in R.



The two options are:



1. Write everything in one file. No sharing of functions.

2. Write libraries - but you *have to package it* first to use it.



Neither is a good option. how you I share functions across two scripts?



there is "source()"

But are there any other way?

For example, in python, what I do is create common functions in a separate

file (say, called A), use those functions from file B by including it like I


would any other library. Then when I'm ready to 'release' it, I can package

the library and the script...



I did find something:-

http://www.ma.hw.ac.uk/~stan/R/Rnotes.pdfsays
:--



To create and edit functions, use the (built-in) R function edit. (As usual,
type ?edit at

the command prompt for details|see Section 10.)

Alternatively the function source|also available via the File menu|can be
used to input

lengthy function denitions from an externally edited le. (The function dump
will write an

existing function denition to a file.)

But then source() also ,not only loads but parses the file too.


https://stat.ethz.ch/pipermail/r-help/2007-October/142938.html

You  can save one or more functions and datasets to a file (see ?save) then
on starting another session attach that file (see ?attach).

The process is like:---



foo <- function(x) mean(as.numeric(x), trim = 0.3)

save(foo, file = "myproject/rfunctions/saved.rda")



then, when starting a new session, use



attach("myproject/rfunctions/saved.rda")



The .rda extension on the filename is commonly used for saved R data

sets but you can also have function definitions in a saved file.

Are these the only ways,and the best ways,to do what I want?


*--
Thanks
Moumita*

-- 
Thanks
Moumita

[[alternative HTML version deleted]]

__
R-help@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.


[R] Segmentation Fault occured while connecting to the database

2009-02-17 Thread Moumita Das
Hi All,
Can anyone help me please?I don't know much about segmentation faults.I
understand what it is,but why my script's throwing the error i don't know.

This is my main function:

*main<-function()*

*{*

*dbName<-"xyz_database"*

*hostName<-"xyz.com"*

*con<-myDbconnect(dbName,hostName) *

**

*#Fetching exact sub group names*

*sub_grp_exact_num<-getSbGrpExactNum(con)*

*sub_grp_exact_num_data<-sub_grp_exact_num$matrix*

*sub_grp_exact_num_data_size<-sub_grp_exact_num$dim*

there's is some other code following the abovei thought
this much code is enough to explain my problem..error occurs when the
myDbconnect function is called at teh third line
**

*}*

myDbconnect  function is here:--

*myDbconnect<-function(dbName, hostName)*

*{*

*print("myDbconnect ")*

*drv<-MySQL()*

*#print(drv)*


*con <- dbConnect(drv, user="xyz", password="xyz",dbname =
dbName, host = hostName)*

*#return(con)*

*}*

When  print("myDbconnect print") is the first line of the myDbconnect
function  "myDbconnect print" gets printed.Though followed by  error
messages,shown below:-

*> source("new_regression.R")*

*Loading required package: DBI*

*[1] "myDbconnect print"*

* *** caught segfault 

*address 0x55, cause 'memory not mapped'*

* *

*Traceback:*

* 1: .Call("RS_MySQL_newConnection", drvId, con.params, groups,
default.file, PACKAGE = .MySQLPkgName)*

* 2: mysqlNewConnection(drv, ...)*

* 3: .class1(object)*

* 4: .class1(object)*

* 5: is(object, Cl)*

* 6: .valueClassTest(standardGeneric("dbConnect"), "DBIConnection",
"dbConnect")*

* 7: dbConnect(drv, user = "xyz", password = "xyz", dbname = dbName, host
= hostName)*

* 8: myDbconnect(dbName, hostName)*

* 9: main()*

*10: eval.with.vis(expr, envir, enclos)*

*11: eval.with.vis(ei, envir)*

*12: source("new_regression.R")*

* *

*Possible actions:*

*1: abort (with core dump)*

*2: normal R exit*

*3: exit R without saving workspace*

*4: exit R saving workspace*

*Selection:*

Now  if I change the position of the print statement  from first line to
fourth line after  dbConnect function:--

myDbconnect<-function(dbName, hostName)

{

drv<-MySQL()

#print(drv)

con <- dbConnect(drv, user="xyz", password="xyz",dbname =
dbName, host = hostName)

print("myDbconnect  print")

#return(con)

}

In this case the text  ("myDbconnect  print") is not printed ,otherwise what
I see is same as above i.e.:--

> source("new_regression.R")

Loading required package: DBI

*** caught segfault ***

address 0x55, cause 'memory not mapped'

Traceback:

 1: .Call("RS_MySQL_newConnection", drvId, con.params, groups,
default.file,
PACKAGE = .MySQLPkgName)

 2: mysqlNewConnection(drv, ...)

 3: .class1(object)

 4: .class1(object)

 5: is(object, Cl)

 6: .valueClassTest(standardGeneric("dbConnect"), "DBIConnection",
"dbConnect")

 7: dbConnect(drv, user = "xyz", password = "xyz", dbname = dbName, host
= hostName)

 8: myDbconnect(dbName, hostName)

 9: main()

10: eval.with.vis(expr, envir, enclos)

11: eval.with.vis(ei, envir)

12: source("new_regression.R")



Possible actions:

1: abort (with core dump)

2: normal R exit

3: exit R without saving workspace

4: exit R saving workspace

Selection:

*CONCLUSION:-- So the problem arises in the* *dbconnect function* *inside
myDbconnect  function.*

*i.e this line :--*

con <- dbConnect(drv, user="xyz", password="xyz",dbname = dbName, host =
hostName)

It's a segfault. A segmentation fault occurs when a program *attempts to
access a memory location that it is not allowed to access*, or *attempts to
access a memory location in a way that is not allowed* (for example,
attempting to write to a read-only location, or to overwrite part of the
operating system).Don't understand how I am trying to do any of these
incorrect operations.

Moreover  *traceback()  *is a function in R that is used for debugging ;
prints the call stack of the last uncaught error, i.e., the sequence of
calls that lead to the error.I have not used it anywhere in  my script
but  still
it shows the errors.



P.S:--- I  found these links,buti don't understand,where am I going wrong
:--

http://tolstoy.newcastle.edu.au/R/e2/devel/06/12/1436.html

http://www.ens.gu.edu.au/ROBERTK/R/HELP/00a/0111.HTML

http://tolstoy.newcastle.edu.au/R/e2/devel/06/12/1438.html


Any help is welcome..Even if anybody doesn't know to solve the problem,is
there anyother way ,i can get some more information,out of my script
regarding the cause of the error.do i need to make any changes,somewhere
else other than the script,to get rid of this problem.

-- 
Thanks in advance
Moumita


-- 
Thanks
Moumita

[[alternative HTML version deleted]]

___

[R] Added system Info:--Segmentation Fault occured while connecting to the database

2009-02-17 Thread Moumita Das
Hi All,
Wanted to add some more information ,regarding my problem.
configuration of teh OS and R:---
Linux 2.6.18-6-686
> R.Version()
$platform
[1] "i486-pc-linux-gnu"

$arch
[1] "i486"

$os
[1] "linux-gnu"

$system
[1] "i486, linux-gnu"

$status
[1] "Patched"

$major
[1] "2"

$minor
[1] "4.0"

$year
[1] "2006"

$month
[1] "11"

$day
[1] "25"

$`svn rev`
[1] "39997"

$language
[1] "R"

$version.string
[1] "R version 2.4.0 Patched (2006-11-25 r39997)"



-- 
Thanks
Moumita

[[alternative HTML version deleted]]

__
R-help@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.


[R] Added system Info:--Segmentation Fault occured while connecting to the database

2009-02-17 Thread Moumita Das
Oops !! I had also included just one library in my script  i.e RMySQL.So
sorry for the inconvenience:(
-- 
Thanks
Moumita

[[alternative HTML version deleted]]

__
R-help@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.


[R] Possible Cause of Segmentation Fault

2009-02-17 Thread Moumita Das
Hi All,

If you have already finished reading my previous emails regarding
segmentation fault , please have a look at this .I think this may help you
to diagnose the reason for the segmentation fault and help me,because i
don't understand much.

Rather than running the script using  the command "
source("new_regression.R") ", what I did was ,simply typed in the  commands
in R-prompt  and the results were:



> drv<-MySQL()

> drv



> dbConnect(drv, user="xyz", password="xyz",dbname =xyz_database, host =
xyz.com)

Error in mysqlNewConnection(drv, ...) : *object "xyz.com" not found*

* *

* *

Thanks

Moumita

[[alternative HTML version deleted]]

__
R-help@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.


[R] Segmentation Fault still exists

2009-02-23 Thread Moumita Das
Hi All,
Sorry to bother everyone again.Ofcourse  Prof Ripley ,Yihui and Uwe had
replied to my email.But this segmentation fault error was not solved.I agree
with Prof Ripley,as he said my R and all other configurations,are very
old.But what i don't understand is ,i was able to run analysis till few days
before,and why suddenly this error.

*The configuartions i use:---*

*R-version
*

*> version*

*   _*

*platform   i486-pc-linux-gnu*

*arch   i486*

*os linux-gnu*

*system i486, linux-gnu*

*status Patched*

*major  2*

*minor  4.0*

*year   2006*

*month  11*

*day25*

*svn rev39997*

*language   R*

* *

*R-Package   Version  *

*DBI  "0.1-11" *

*RMySQL  "0.5-11"  *

* *

*MySQL version: 5.0.32*


*A small R- program* *also doesn't run now*,whereas with these same
configurations,i ran correlation analysis,regression analysis for my
datasets.

Now if i do this :---

*library(RMySQL)

myDbconnect<-function(dbName,hostName)
{
print("myDbconnect print before driver")
drv<-MySQL()
#print(drv)
print("myDbconnect print after driver")
#con <- dbConnect(drv, user="xyz", password="xyz",dbname = dbName, host
= hostName)
con<-dbConnect(drv)

print("myDbconnect print after connecting the db")
return(con)
}




main<-function()
{

 print("inside main")
 dbName<-"AHP2006"
hostName<-"mia.foresightint.com"
con<-myDbconnect(dbName,hostName)
 print("hello hello")
}

main()*

Before driver and after driver both the text inside print function are
printed.But in the dbconnect some error occurs.*I do not have access to the
packages,my seniors have that*.All i do is with the scripts.All i read about
segmentation fault is some faulty C-code in the packages.I think the problem
is with DBI package.Just wanted to know* other than any error in the
packages, can a segmentation fault happen*?Because i was not informed about
any changes made in the packages.Where am i going wrong?

*Error:---*

*> source("sample.R")
Loading required package: DBI
[1] "inside main"
[1] "myDbconnect print before driver"
[1] "myDbconnect print after driver"

 *** caught segfault ***
address 0x55, cause 'memory not mapped'

Traceback:
 1: .Call("RS_MySQL_newConnection", drvId, con.params, groups,
default.file, PACKAGE = .MySQLPkgName)
 2: mysqlNewConnection(drv, ...)
 3: .class1(object)
 4: .class1(object)
 5: is(object, Cl)
 6: .valueClassTest(standardGeneric("dbConnect"), "DBIConnection",
"dbConnect")
 7: dbConnect(drv, user = "xyz", password = "xyz", dbname = dbName, host
= hostName)
 8: myDbconnect(dbName, hostName)
 9: main()
10: eval.with.vis(expr, envir, enclos)
11: eval.with.vis(ei, envir)
12: source("sample.R")

Possible actions:
1: abort (with core dump)
2: normal R exit
3: exit R without saving workspace
4: exit R saving workspace
Selection:


*
I tried doing some debugging.But could not find a solution.
If i do back tracing :

> *dbConnect*

standardGeneric for "dbConnect" defined from package "DBI"

  defined with value class: "DBIConnection"



function (drv, ...)

.valueClassTest(standardGeneric("dbConnect"), "DBIConnection",

"dbConnect")



Methods may be defined for arguments: drv



> *methods:::.valueClassTest*

*function (object, classes, fname)*

*{*

*if (length(classes) > 0) {*

*for (Cl in classes) if (is(object, Cl))*

*return(object)*

*stop(gettextf("invalid value from generic function \"%s\", class
\"%s\", expected %s",*

*fname, class(object), paste("\"", classes, "\"",*

*sep = "", collapse = " or ")), domain = NA)*

*}*

*object*

*}*

*> mysqlNewConnection*

*function (drv, dbname = "", username = "", password = "", host = "",*

*unix.socket = "", port = 0, client.flag = 0, groups = NULL,*

*default.file = character(0))*

*{*

*if (!isIdCurrent(drv))*

*stop("expired manager")*

*con.params <- as.character(c(username, password, host, dbname,*

*unix.socket, port, client.flag))*

*groups <- as.character(groups)*

*if (length(default.file) == 1) {*

*default.file <- file.path(dirname(default.file),
basename(default.file))*

*if (!file.exists(default.file))*

*stop(sprintf("mysql default file %s does not exist",*

*default.file))*

*}*

*drvId <- as(drv, "integer")*

*conId <- .Call("RS_MySQL_newConnection", drvId, con.params,*

*groups, default.file, PACKAGE = .MySQLPkgName)
// here it gets stopped,traceback line 1*

*new("MySQLConnection", Id = conId)*

*}*

-- 
Thanks in advance
Moumita

[[alternative HTML version deleted]]

__
R-help@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, minima

[R] if condition doesn't evaluate to True/False

2009-04-29 Thread Moumita Das
Hi friends,
Please help me with this bug.

*Bug in my code:*

In this variable sub_grp_whr_cls_data[sbgrp_no,1] I store the where
clause.every sub group has a where condition linked with it.

Database1


Where clause  was  not found for a particular subgroup,
sub_grp_whr_cls_data[sbgrp_no,1]  value was NULL

So the condition (*sub_grp_whr_cls_data[sbgrp_no,1]=="NULL" ||
sub_grp_whr_cls_data[sbgrp_no,1]==""*) should evaluate to TRUE ,but it
evaluated to NA

So the if block where I used the the condition threw error

If(*sub_grp_whr_cls_data[sbgrp_no,1]=="NULL" ||
sub_grp_whr_cls_data[sbgrp_no,1]==""*)

i.e if(NA)

Error:--

Error in if (sub_grp_whr_cls_data[sbgrp_no, 1] == "NULL" ||
sub_grp_whr_cls_data[sbgrp_no,  :

  missing value where TRUE/FALSE needed

Comments:-- but when there ‘s no where clause value the condition
(sub_grp_whr_cls_data[sbgrp_no,1]=="NULL"
||sub_grp_whr_cls_data[sbgrp_no,1]=="") should automatically evaluate to *
TRUE*



Database2

Where clause  was  found for a particular subgroup

The condition (sub_grp_whr_cls_data[sbgrp_no,1]=="NULL"
||sub_grp_whr_cls_data[sbgrp_no,1]=="") evaluated to FALSE

So if (sub_grp_whr_cls_data[sbgrp_no,1]=="NULL"
||sub_grp_whr_cls_data[sbgrp_no,1]=="") is

If (FALSE) ,control goes to the else part.

This is exactly what is expected of the program.

*QUERY:-- **If the condition evaluates to FALSE  when a where condition is
available why doesn’t it evaluate to TRUE when a where condition available
is NULL or no where condition is available.*

Here I have taken the example of two databases where I tried to get the
where clause for subgroup 1.In case of Database1 it was not available in
case of Databse2 it was available.But the problem may appear for the same
database also, when where clause is available for say one subgroup and not
for the other.

-- 
Thanks
Moumita

[[alternative HTML version deleted]]

__
R-help@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.


[R] Partial correlation function required

2009-05-11 Thread Moumita Das
-- Forwarded message --
From: 
Date: Mon, May 11, 2009 at 10:24 PM
Subject: The results of your email commands
To: das.moumita.onl...@gmail.com


The results of your email command are provided below. Attached is your
original message.

- Results:
   Ignoring non-text/plain MIME parts

- Unprocessed:
   What is the function for partial correlation.The function which i found
   here:-- http://www.yilab.gatech.edu/pcor.Rand used the recursive
   version, showed errors while computing partial correlation,where the
third
   variable i.e controlled variable for a pair is more than that .That is
when
   i had more than one third variable ,it always became an infinite loop,it
   else.
   # By using recursive formula
   pcor.rec <- function(x,y,z,method="p",na.rm=T){
   #
   x <- c(x)
   y <- c(y)
   z <- as.data.frame(z)
   if(dim(z)[2] == 0){
   stop("There should be given data\n")
   }
   data <- data.frame(x,y,z)
   if(na.rm == T){
   data = na.omit(data)
   }

- Ignored:

   # recursive formula
   if(dim(z)[2] == 1){
   tdata <- na.omit(data.frame(data[,1],data[,2]))
   rxy <- cor(tdata[,1],tdata[,2],m=method)

   tdata <- na.omit(data.frame(data[,1],data[,-c(1,2)]))
   rxz <- cor(tdata[,1],tdata[,2],m=method)

   tdata <- na.omit(data.frame(data[,2],data[,-c(1,2)]))
   ryz <- cor(tdata[,1],tdata[,2],m=method)

   rxy.z <- (rxy - rxz*ryz)/( sqrt(1-rxz^2)*sqrt(1-ryz^2) )

   return(rxy.z)
   }else{
   x <- c(data[,1])
   y <- c(data[,2])
   z0 <- c(data[,3])
   zc <- as.data.frame(data[,-c(1,2,3)])

   rxy.zc <- pcor.rec(x,y,zc,method=method,na.rm=na.rm)
   rxz0.zc <- pcor.rec(x,z0,zc,method=method,na.rm=na.rm)
   ryz0.zc <- pcor.rec(y,z0,zc,method=method,na.rm=na.rm)

   rxy.z <- (rxy.zc - rxz0.zc*ryz0.zc)/(
sqrt(1-rxz0.zc^2)*sqrt(1-ryz0.zc^2) )
   return(rxy.z)
   }
   }

   and this piece of code also i tried to use.

   Rinv <- solve <http://wiki.r-project.org/rwiki/rhelp.php?id=solve>(R)
   D <- diag <http://wiki.r-project.org/rwiki/rhelp.php?id=diag>(1 / sqrt
   <http://wiki.r-project.org/rwiki/rhelp.php?id=sqrt>(diag
   <http://wiki.r-project.org/rwiki/rhelp.php?id=diag>(Rinv)))
   P <- -D <http://wiki.r-project.org/rwiki/rhelp.php?id=D> %*% Rinv %*%
   D <http://wiki.r-project.org/rwiki/rhelp.php?id=D>

   where R is teh correlation matrix.
   but NaN error at for
   sqrt <http://wiki.r-project.org/rwiki/rhelp.php?id=sqrt>(diag
   <http://wiki.r-project.org/rwiki/rhelp.php?id=diag>(Rinv) were
   generated.





http://wiki.r-project.org/rwiki/doku.php?id=tips:data-matrices:part_corr&s=correlation


   Any convinient function for partial correlation for both one
   controlled variable or more.



   --
   Thanks
   Moumita

- Done.



-- Forwarded message --
From: Moumita Das 
To: r-help-requ...@r-project.org
Date: Mon, 11 May 2009 22:23:33 +0530
Subject: partial correlation function
Hi friends,
What is the function for partial correlation.The function which i found
here:-- http://www.yilab.gatech.edu/pcor.Rand used the recursive
version, showed errors while computing partial correlation,where the third
variable i.e controlled variable for a pair is more than that .That is when
i had more than one third variable ,it always became an infinite loop,it
else.

# By using recursive formula
pcor.rec <- function(x,y,z,method="p",na.rm=T){
#

x <- c(x)
y <- c(y)
z <- as.data.frame(z)

if(dim(z)[2] == 0){
stop("There should be given data\n")

}

data <- data.frame(x,y,z)

if(na.rm == T){
data = na.omit(data)
}

# recursive formula
if(dim(z)[2] == 1){
tdata <- na.omit(data.frame(data[,1],data[,2]))
rxy <- cor(tdata[,1],tdata[,2],m=method)

tdata <- na.omit(data.frame(data[,1],data[,-c(1,2)]))
rxz <- cor(tdata[,1],tdata[,2],m=method)

tdata <- na.omit(data.frame(data[,2],data[,-c(1,2)]))
ryz <- cor(tdata[,1],tdata[,2],m=method)

rxy.z <- (rxy - rxz*ryz)/( sqrt(1-rxz^2)*sqrt(1-ryz^2) )

return(rxy.z)
}else{
x <- c(data[,1])
y <- c(data[,2])
z0 <- c(data[,3])
zc <- as.data.frame(data[,-c(1,2,3)])

rxy.zc <- pcor.rec(x,y,zc,method=method,na.rm=na.rm)
rxz0.zc <- pcor.rec(x,z0,zc,method=method,na.rm=na

[R] Fwd: Cannot allocate a new database connection error

2009-05-16 Thread Moumita Das
-- Forwarded message --
From: Moumita Das 
Date: Sat, May 16, 2009 at 2:26 PM
Subject: Cannot allocate a new database connection error
To: r-help-requ...@r-project.org


Hi friends,
why do i keep getting this error?The program runs, twice and every third
time i get this error.I have to quit.Again get teh R-prompt and then run the
script.

*Error in mysqlNewConnection(drv, ...) :
  RS-DBI driver: (�...@`qe@°
°
cannot allocate a new connection -- maximum of 16 connections already
opened)
Error in is(object, Cl) :
  error in evaluating the argument 'conn' in selecting a method for function
'dbSendQuery'
Error in is(object, Cl) :
  error in evaluating the argument 'res' in selecting a method for function
'fetch'*


*this is my DB connection function*
*myDbConnect <- function (dbName, hostName) {
  drv<-MySQL()
  con <- dbConnect(drv, user="xyz", password="xyz",dbname = dbName, host
= hostName)
return(con)
}*


everytime i need ,Db connection , i used in this way:



This is the structure of my code:--
main <- function ()
 {
  #Looping through subgroups
   for(sub_group_num_loopcounter in 1:sub_group_num_data_size[1])
   {
 #Fetching the where clause for the particular subgroup
*sub_group_where_condition <-
fetch(dbSendQuery(myDbConnect(dbName,hostName), paste(c("SELECT where_clause
FROM sub_grp where

num=",sub_group_num_data[sub_group_num_loopcounter,1]),collapse="")), n =
-1)  *
}
dbDisconnect(con)
dbListConnections(MySQL())
l<-list()

}

Where should i close the DB connection  or use one single connection
throughout the prograam.

-- 
Thanks
Moumita



-- 
Thanks
Moumita

[[alternative HTML version deleted]]

__
R-help@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.


[R] Query regarding na.omit function

2009-05-22 Thread Moumita Das
Hi friends,
I have a query regarding na.omit function.Please ,someone help me.

I have a function
xyz_function<-function(arguments)
{
   some code
   return(list(matrix=dataset))
}

xyz_function_returnvalue<-xyz_function(passed argumentss)

*Case-I*
xyz_function_returnvalue_deletingNArows<-na.omit((xyz_function_returnvalue))
*Case-II*
 
xyz_function_returnvalue_dataframe_deletingNArows<-na.omit(as.data.frame((pair_raw_data$matrix)))

Both case I and II don't work.My dataset has rows with NA values,that's for
sure.



Whereas this simple code,works fine.I mean from the data frame the rows
containing NA values could be easily deleted.

DF <- data.frame(x = c(1, 2, 3), y = c(0, 10, NA))
DF<-na.omit(DF)
print(DF)

-- 
Thanks
Moumita

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Query regarding na.omit function

2009-05-22 Thread Moumita Das
Hi Jim,

xyz_function<-function(arguments)

> {
>some code


pair_raw_data<-changeMissingValuestoNA(pair_raw_data$matrix,pair_raw_data$dim,missing_values)


>
>return(list(matrix=pair_raw_data))
> }

Type of my dataset was a "list".I tried checking that ,changing my dataset
to some other types.

Thanks
Moumita

On Fri, May 22, 2009 at 7:11 PM, Moumita Das
wrote:

>
> Hi friends,
> I have a query regarding na.omit function.Please ,someone help me.
>
> I have a function
> xyz_function<-function(arguments)
> {
>some code
>return(list(matrix=dataset))
> }
>
> xyz_function_returnvalue<-xyz_function(passed argumentss)
>
> *Case-I*
>
> xyz_function_returnvalue_deletingNArows<-na.omit((xyz_function_returnvalue))
> *Case-II*
>
>  
> xyz_function_returnvalue_dataframe_deletingNArows<-na.omit(as.data.frame((pair_raw_data$matrix)))
>
> Both case I and II don't work.My dataset has rows with NA values,that's for
> sure.
>
>
>
> Whereas this simple code,works fine.I mean from the data frame the rows
> containing NA values could be easily deleted.
>
> DF <- data.frame(x = c(1, 2, 3), y = c(0, 10, NA))
> DF<-na.omit(DF)
> print(DF)
>
> --
> Thanks
> Moumita
>



-- 
Thanks
Moumita

[[alternative HTML version deleted]]

__
R-help@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.


[R] Or operator on working on the r-objects doesn't generate a logical value

2009-05-25 Thread Moumita Das
Hi friends,
Can somebody help me out please?

I have to create a string for a particular if condition , with some
values(returned by function1) which are always variable.

*Step-I* Suppose function1 returns a dataframe like this,shown below with
two values 3 and 4:---
   x
1  3
2  4

*STEP-II  *For creating the string with these values returned by function 1
i have another function2.
These values when passed to function 2 ,returns something like this:---
> source("myscript.R")
[1] "dataset[record_num,item_num]=='3' || dataset[record_num,item_num]=='4'
"
type of the above text prepared is "list"
Say it is text<- dataset[record_num,item_num]=='3' ||
dataset[record_num,item_num]=='4'

*Step-III* Now this 'text ' is passed to another function3 where it is
clubbed to some other  text to prepare a bigger text.
Like this(which will be used as an if-condition later) and then i tried
printing it :--
print ( (text)  || dataset[record_num,item_num]=="NUL" ||
dataset[record_num,item_num]=="" || dataset[record_num,item_num]=="M" )

*ERROR:*
I keep getting this error:--
Error in (text) || dataset[record_num, item_num] == "NUL" :
  invalid 'x' type in 'x || y'

What i want is this:--

*if ( dataset[record_num,item_num]=="3"  ||
dataset[record_num,item_num]=="4" || dataset[record_num,item_num]=="NUL" ||
dataset[record_num,item_num]=="" || dataset[record_num,item_num]=="M" )*

*I tried doing this in a diffrent way also:--*

*predefined_text<- dataset[record_num,item_num]=="NUL" ||
dataset[record_num,item_num]=="" || dataset[record_num,item_num]=="M"
text was prepared like this:--
text<- dataset[record_num,item_num]=='3' ||
dataset[record_num,item_num]=='4'

ifCondition<-paste(**predefined_text**,**text**,sep=" || ")
**Now say **dataset[record_num,item_num] has value "NULL" so predefined_text
gets value TRUE so if -condition is this:--*
*ifCondition<-paste(**predefined_text**,**text**,sep=" || ")
** print(ifCondition)*

ERROR:---
[1] "TRUE || (dataset[record_num,item_num]=='3' ||
dataset[record_num,item_num]=='4')"
[2] "TRUE || (c(3, 4))"
[3] "TRUE || (list(x = c(3, 4)))"
Error in if (ifCondition) { : argument is not interpretable as logical
In addition: Warning message:
In if (ifCondition) { :
  the condition has length > 1 and only the first element will be used

My desired result,(when *dataset[record_num,item_num] has value "NULL")  *is:--
" *TRUE || (dataset[record_num,item_num]=='3' ||
dataset[record_num,item_num]=='4')* "
Why doesn't this work?

-- 
Thanks in advance
Moumita

[[alternative HTML version deleted]]

__
R-help@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.


[R] how to make the dynamically creted string work inside if as a condition

2009-06-06 Thread Moumita Das
Hi,
How to make an if condition work,  if the condition inside if() is created
dynamically  ,and that is a string .If i type teh dynamically created string
the if works fine but when dynamically created,it is a string and going
inside the if() ,an error is thrown saying : rgument is not logical ..I even
tried changing teh mode of the string to logical,but it doesn't work

Say my dynamically created string is :--

str<- name=='tom' || name=='harry' || name=='tina'
where the names are diffrent for diffrent DBs.

if(name=='tom' || name=='harry' || name=='tina' )
{
 some code
}

If i do this
if(str)
{

 some code
}

It doesn't work:(
-- 


Thanks
Moumita

[[alternative HTML version deleted]]

__
R-help@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.


[R] Error: system is computationally singular: reciprocal condition number

2009-06-25 Thread Moumita Das
I get this error while computing partial correlation.


*Error in solve.default(Szz) :
  system is computationally singular: reciprocal condition number =
4.90109e-18*

Why is it?Can anyone give me some idea ,how do i get rid it it?

This is the function i use for calculating partial correlation.


pcor.mat <- function(x,y,z,method="p",na.rm=T){


x <- c(x)
y <- c(y)
z <- as.data.frame(z)



if(dim(z)[2] == 0){
stop("There should be given data\n")
}

data <- data.frame(x,y,z)

if(na.rm == T){
data = na.omit(data)
}

xdata <- na.omit(data.frame(data[,c(1,2)]))
Sxx <- cov(xdata,xdata,m=method)

xzdata <- na.omit(data)
xdata <- data.frame(xzdata[,c(1,2)])
zdata <- data.frame(xzdata[,-c(1,2)])
Sxz <- cov(xdata,zdata,m=method)

zdata <- na.omit(data.frame(data[,-c(1,2)]))
Szz <- cov(zdata,zdata,m=method)


# is Szz positive definite?
zz.ev <- eigen(Szz)$values
if(min(zz.ev)[1]<0){

stop("\'Szz\' is not positive definite!\n")
}

# partial correlation
Sxx.z <- Sxx - Sxz %*% solve(Szz) %*% t(Sxz)

print(Sxx.z) # this gets printed

rxx.z <- cov2cor(Sxx.z)[1,2] #some problem in this function
function (V)
{
   print("cov2cor")
   p <- (d <- dim(V))[1]
if (!is.numeric(V) || length(d) != 2L || p != d[2L])
stop("'V' is not a square numeric matrix")
Is <- sqrt(1/diag(V))
if (any(!is.finite(Is)))
warning("diag(.) had 0 or NA entries; non-finite result is
doubtful")
r <- V
r[] <- Is * V * rep(Is, each = p)
r[cbind(1L:p, 1L:p)] <- 1
r
}
return(rxx.z)
}

-- 
Thanks
Moumita

[[alternative HTML version deleted]]

__
R-help@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.


[R] A new R-community in Orkut

2009-06-28 Thread Moumita Das
Hi friends,
I just created a new R- community in Orkut.Please do join.And we can stay
connected.
Name of the community:
Statistics & R-language
-- 
Thanks
Moumita

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Error: system is computationally singular: reciprocal condition number

2009-06-28 Thread Moumita Das
I get this error  on using the, traceback() function :--
> traceback()
10: .Call("La_dgesv", a, b, tol, PACKAGE = "base")
9: solve.default(Szz)
8: solve(Szz)
7: pcor.mat(firstvalue, secondvalue, third_var, method, na.rm = T)
6: PartialCorr_Calculation(value1, value2, third_var, method = "pearson",
   na.rm = T)
5: Partial(contrld_third_var(rowvalues$matrix1, rowvalues$matrix2,
   x <- stringOfItemCategoryToDataFrameOfItemCategory,
item_category_table,
   pcor_type <- "ic"), data1, data2, pcor_thirdvar_type <- "all")
4: main()
3: eval.with.vis(expr, envir, enclos)
2: eval.with.vis(ei, envir)
1: source("correlationFP.R")

what is this error ".*Call("La_dgesv", a, b, tol, PACKAGE = "base")*"  how
can i rectify it?
I don't know statistics...going mad ,debugging this problem..
any help is highly appreciated !! :)

Thanks in advance
Moumita

On Thu, Jun 25, 2009 at 8:29 PM, Moumita Das
wrote:

>
> I get this error while computing partial correlation.
>
>
> *Error in solve.default(Szz) :
>   system is computationally singular: reciprocal condition number =
> 4.90109e-18*
>
> Why is it?Can anyone give me some idea ,how do i get rid it it?
>
> This is the function i use for calculating partial correlation.
>
>
> pcor.mat <- function(x,y,z,method="p",na.rm=T){
>
>
> x <- c(x)
> y <- c(y)
> z <- as.data.frame(z)
>
>
>
> if(dim(z)[2] == 0){
> stop("There should be given data\n")
> }
>
> data <- data.frame(x,y,z)
>
> if(na.rm == T){
> data = na.omit(data)
> }
>
> xdata <- na.omit(data.frame(data[,c(1,2)]))
> Sxx <- cov(xdata,xdata,m=method)
>
> xzdata <- na.omit(data)
> xdata <- data.frame(xzdata[,c(1,2)])
> zdata <- data.frame(xzdata[,-c(1,2)])
> Sxz <- cov(xdata,zdata,m=method)
>
> zdata <- na.omit(data.frame(data[,-c(1,2)]))
> Szz <- cov(zdata,zdata,m=method)
>
>
> # is Szz positive definite?
> zz.ev <- eigen(Szz)$values
> if(min(zz.ev)[1]<0){
>
> stop("\'Szz\' is not positive definite!\n")
> }
>
> # partial correlation
> Sxx.z <- Sxx - Sxz %*% solve(Szz) %*% t(Sxz)
>
> print(Sxx.z) # this gets printed
>
> rxx.z <- cov2cor(Sxx.z)[1,2] #some problem in this function
> function (V)
> {
>print("cov2cor")
>p <- (d <- dim(V))[1]
> if (!is.numeric(V) || length(d) != 2L || p != d[2L])
> stop("'V' is not a square numeric matrix")
> Is <- sqrt(1/diag(V))
> if (any(!is.finite(Is)))
> warning("diag(.) had 0 or NA entries; non-finite result is
> doubtful")
> r <- V
> r[] <- Is * V * rep(Is, each = p)
> r[cbind(1L:p, 1L:p)] <- 1
> r
> }
> return(rxx.z)
> }
>
> --
> Thanks
> Moumita
>



-- 
Thanks
Moumita

[[alternative HTML version deleted]]

__
R-help@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.


[R] ERROR: system is computationally singular: reciprocal condition number = 4.90109e-18

2009-06-28 Thread Moumita Das
Hi All,
This is my R-version information:---
> version
   _
platform   i486-pc-linux-gnu
arch   i486
os linux-gnu
system i486, linux-gnu
status
major  2
minor  7.1
year   2008
month  06
day23
svn rev45970
language   R
version.string R version 2.7.1 (2008-06-23)

While calculating partial correlation for a dataset ,i keep getting this
error :--
*Error in solve.default(Szz) :
  system is computationally singular: reciprocal condition number =
4.90109e-18*



On using the traceback() function i get this:--
> traceback()
10: *.Call("La_dgesv", a, b, tol, PACKAGE = "base")*
9: solve.default(Szz)
8: solve(Szz)
7: pcor.mat(firstvalue, secondvalue, third_var, method, na.rm = T)
6: PartialCorr_Calculation(value1, value2, third_var, method = "pearson",
   na.rm = T)
5: Partial(contrld_third_var(rowvalues$matrix1, rowvalues$matrix2,
   x <- stringOfItemCategoryToDataFrameOfItemCategory,
item_category_table,
   pcor_type <- "ic"), data1, data2, pcor_thirdvar_type <- "all")
4: main()
3: eval.with.vis(expr, envir, enclos)
2: eval.with.vis(ei, envir)
1: source("correlationFP.R")

In pcor.mat function :--
# By using var-cov matrix
pcor.mat <- function(x,y,z,method="p",na.rm=T){

#print("pcor.mat")
x <- c(x)
y <- c(y)
z <- as.data.frame(z)

m<- identical(all.equal(x, y), TRUE)
#print(m)
if(  m=="TRUE")
{
print("inside equality---")
return(1)
}


if(dim(z)[2] == 0){
stop("There should be given data\n")
}

data <- data.frame(x,y,z)

if(na.rm == T){
data = na.omit(data)
}

xdata <- na.omit(data.frame(data[,c(1,2)]))
Sxx <- cov(xdata,xdata,m=method)

xzdata <- na.omit(data)
xdata <- data.frame(xzdata[,c(1,2)])
zdata <- data.frame(xzdata[,-c(1,2)])
Sxz <- cov(xdata,zdata,m=method)

zdata <- na.omit(data.frame(data[,-c(1,2)]))
Szz <- cov(zdata,zdata,m=method)


# is Szz positive definite?
zz.ev <- eigen(Szz)$values
if(min(zz.ev)[1]<0){

stop("\'Szz\' is not positive definite!\n")
}

# partial correlation
Sxx.z <- Sxx - Sxz %*% solve(Szz) %*% t(Sxz) # this gets printed




rxx.z <- cov2cor(Sxx.z)[1,2] # probably error in this function cov2cor




return(rxx.z)
}

for some other datasets this pcor.mat function works fine.
The solve.default function is this:---
solve.default<-function(a, b, tol = ifelse(LINPACK, 1e-07,
.Machine$double.eps),LINPACK = FALSE, ...)
{

if (is.complex(a) || (!missing(b) && is.complex(b))) {
a <- as.matrix(a)
if (missing(b)) {
if (nrow(a) != ncol(a))
stop("only square matrices can be inverted")
b <- diag(1 + (0+0i), nrow(a))
colnames(b) <- rownames(a)
}
else if (!is.complex(b))
b[] <- as.complex(b)
if (!is.complex(a))
a[] <- as.complex(a)
return(if (is.matrix(b)) {
if (ncol(a) != nrow(b)) stop("'b' must be compatible with 'a'")
rownames(b) <- colnames(a)
.Call("La_zgesv", a, b, PACKAGE = "base")
} else drop(.Call("La_zgesv", a, as.matrix(b), PACKAGE = "base")))
}
if (is.qr(a)) {
warning("solve.default called with a \"qr\" object: use 'qr.solve'")
return(solve.qr(a, b, tol))
}
if (!LINPACK) {
a <- as.matrix(a)
if (missing(b)) {
if (nrow(a) != ncol(a))
stop("only square matrices can be inverted")
b <- diag(1, nrow(a))
colnames(b) <- rownames(a)
}
else storage.mode(b) <- "double"
storage.mode(a) <- "double"
return(if (is.matrix(b)) {
if (ncol(a) != nrow(b)) stop("'b' must be compatible with 'a'")
rownames(b) <- colnames(a)
.Call("La_dgesv", a, b, tol, PACKAGE = "base")
} else drop(.Call("La_dgesv", a, as.matrix(b), tol, PACKAGE =
"base")))
}
a <- qr(a, tol = tol)
nc <- ncol(a$qr)
if (a$rank != nc)
stop("singular matrix 'a' in 'solve'")
if (missing(b)) {
if (nc != nrow(a$qr))
stop("only square matrices can be inverted")
b <- diag(1, nc)
colnames(b) <- rownames(a$qr)
}
qr.coef(a, b)
}

So what has to be done in the "base" package to get rid of this error.


-- 
Thanks
Moumita

[[alternative HTML version deleted]]

__
R-help@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.


[R] Partial Correlation

2009-07-13 Thread Moumita Das
Why do we get Partial correlation values greater than 1?

 I have used the default function pcor.mat :--

I have manipulated the default pcor.mat function a bit so ignore tha
variables corr_type,element1_in_no,element2_in_no,P.Please ignore the
“pairwise” section and have a look at athe “listwise ” part i.e else part.

*pcor.mat <-
function(x,y,z,method="p",na.rm=T,corr_type,element1_in_no,element2_in_no,P){
*

**

*print("pcor.mat")*

*x <- c(x)*

*y <- c(y)*

*z <- as.data.frame(z)*

*print(z)*

*#print("element1_in_no")*

*#print(element1_in_no)*

**

* *

*if(dim(z)[2] == 0){   *

*stop("There should be given data\n")*

*}*

* *

*data <- data.frame(x,y,z)*

**

**

*if(corr_type=="pairwise")*

*{*

**

*print("inside pairwise")*

*rxx.z
<-P[as.numeric(element1_in_no),as.numeric(element2_in_no)]*

*#print("rxx.z")*

*#print(rxx.z)*

**

*return(rxx.z)*

* *

*}*

*else*

*{*

*print("inside listwise")*

*if(na.rm == T){*

*data = na.omit(data)*

*}*

**

*xdata <- na.omit(data.frame(data[,c(1,2)]))
#i1,C1*

*print("printing
xdata...")*

*print(xdata)*

*Sxx <- cov(xdata,xdata,m=method)*

*
print("Sxx...")*

*print(Sxx )*

* *

*xzdata <- na.omit(data)*

*xdata <- data.frame(xzdata[,c(1,2)])*

*zdata <- data.frame(xzdata[,-c(1,2)])*

*print("zdata..")*

*print(zdata)*

*Sxz <- cov(xdata,zdata,m=method)*

*
print("Sxz.
")*

*print(Sxz)*

* *

*zdata <-
na.omit(data.frame(data[,-c(1,2)]))*

*Szz <- cov(zdata,zdata,m=method)*

*print("Szz
")*

*print(Szz)*

*#print("new type par corr")*

*#P<-partialCorr_matrix(data)*

**

*}*

**

**

*# is Szz positive definite?*

*zz.ev <- eigen(Szz)$values*

*if(min(zz.ev)[1]<0){*

**

*stop("\'Szz\' is not positive definite!\n")
*

*}*

**

**

*# partial correlation*

*Sxx.z <- Sxx - Sxz %*% solve(Szz) %*% t(Sxz)*

*print("Sxx.z")*

*print(qr(Sxx.z))*

*rxx.z <- cov2cor(Sxx.z)[1,2]*

**

*return(rxx.z)*

*}*

*Cov2cor function:-*

*cov2cor<-function (V) *

*{*

*   print("inside cov2cor")*

*  *

*   *

*   p <- (d <- dim(V))[1]*

*if (!is.numeric(V) || length(d) != 2L || p != d[2L]) *

*stop("'V' is not a square numeric matrix")*

*Is <- sqrt(1/diag(V))*

*print("Is")*

*print(Is)*

*if (any(!is.finite(Is))) *

*warning("diag(.) had 0 or NA entries; non-finite result is
doubtful")*

*r <- V*

*r[] <- Is * V * rep(Is, each = p)*

* print("r")*

* print(r[])*

* *

*r[cbind(1L:p, 1L:p)] <- 1*

*r*

**

*}*

* *

Sxx , Sxz , Szz  all these three values I have calculated and they match
with SPSS result.

After that I am not understanding why my partial correlation result doesn’t
match with the SPSS result.

Sxx.z <- Sxx - Sxz %*% solve(Szz) %*% t(Sxz)  # how to calculate in
SPSS.After this as you can see in pcor.mat function rxx.z <-
cov2cor(Sxx.z)[1,2] is computed.



Don’t know where things are going wrong.**

*I will attach the datas of categories and items which form the categories.*

*Category 1 has items -1,5 *

*Category 2 has items – 2,4,6,7,8,9,11*

*Category 3 has items -3,12,14*

*Category 4 has items -10,13,15*

* Category values are actual

[R] LAPACK package

2009-07-14 Thread Moumita Das
Hi All,
Can someone tell me if solve function shown below for my version of R is
proper or not?

I am using R 2.7.2 .Wherever i have used this function ,i got results which
were different from the expected results as computed using  SPSS.

Description of this function says:--
Solve a System of EquationsDescription

This generic function solves the equation a %*% x = b for x, where b can be
either a vector or a matrix.
Usage

solve(a, b, ...)

## Default S3 method:
solve(a, b, tol, LINPACK = FALSE, ...)

Arguments  a a square numeric or complex matrix containing the coefficients
of the linear system. b a numeric or complex vector or matrix giving the
right-hand side(s) of the linear system. If missing, b is taken to be an
identity matrix and solve will return the inverse of a. tol the tolerance
for detecting linear dependencies in the columns of a. If LINPACK is
TRUEthe default is
1e-7, otherwise it is .Machine$double.eps. Future versions of R may use a
tighter tolerance. Not presently used with complex matrices a.
*LINPACK* *logical.
Should LINPACK be used (for compatibility with R < 1.7.0)? Otherwise LAPACK
is used.* *...* *further arguments passed to or from other methods*

*This is the function for my version of R,don't understand if the
discrepancy in results are due to this function.I don't see any mention of
LAPACK in this function :
*
solve.default<-function(a, b, tol = ifelse(LINPACK,  1e-07,
.Machine$double.eps),LINPACK = FALSE, ...)
{

   print("inside solve.default")


if (is.complex(a) || (!missing(b) && is.complex(b))) {
a <- as.matrix(a)
if (missing(b)) {
if (nrow(a) != ncol(a))
stop("only square matrices can be inverted")
b <- diag(1 + (0+0i), nrow(a))
colnames(b) <- rownames(a)
}
else if (!is.complex(b))
b[] <- as.complex(b)
if (!is.complex(a))
a[] <- as.complex(a)
return(if (is.matrix(b)) {
if (ncol(a) != nrow(b)) stop("'b' must be compatible with 'a'")
rownames(b) <- colnames(a)

   print("inside Call La_zgesv  a, b, PACKAGE base")
   retur(NA)

.Call("La_zgesv", a, b, PACKAGE = "base")
#
} else drop(.Call("La_zgesv", a, as.matrix(b), PACKAGE = "base")))
}
if (is.qr(a)) {
warning("solve.default called with a \"qr\" object: use 'qr.solve'")
return(solve.qr(a, b, tol))
}
if (!LINPACK) {
a <- as.matrix(a)
if (missing(b)) {
if (nrow(a) != ncol(a))
stop("only square matrices can be inverted")
b <- diag(1, nrow(a))
colnames(b) <- rownames(a)
}
else storage.mode(b) <- "double"
storage.mode(a) <- "double"
return(if (is.matrix(b)) {
if (ncol(a) != nrow(b)) stop("'b' must be compatible with 'a'")
rownames(b) <- colnames(a)
.Call("La_dgesv", a, b, tol, PACKAGE = "base")
} else drop(.Call("La_dgesv", a, as.matrix(b), tol, PACKAGE =
"base")))
}
a <- qr(a, tol = tol)
nc <- ncol(a$qr)
if (a$rank != nc)
stop("singular matrix 'a' in 'solve'")
if (missing(b)) {
if (nc != nrow(a$qr))
stop("only square matrices can be inverted")
b <- diag(1, nc)
colnames(b) <- rownames(a$qr)
}
qr.coef(a, b)
}


-- 
Thanks
Moumita

[[alternative HTML version deleted]]

__
R-help@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.


[R] Regression function lm() not giving proper results

2009-07-20 Thread Moumita Das
*
*

Hi ,

Can anyone help me please  with this problem?*
*

*CASE-I*

all_raw_data_NAomitted is my data frame.It has columns with names i1 ,i2,
i3,i4…, till i15.It has 291 rows actually ,couldn’t show here.

The data frame looks like this:--

   i1 i2 i3 i4 i5 i6 i7 i8 i9 i10 i11 i12 i13 i14 i15

22  2  2  2  2  2  2  2  2   2   1   2   2 3   2

32  2  2  2  3  2  2  3  3   3   2   3   333

42  2  2  2  2  2  2  1  1   1   2   1   222

62  2  1  2  1  1  2  2  1   1   1   1   22   2

83  2  2  2  3  3  3  2  3   2   3   2   332

92  2  2  2  2  2  3  3  3   2   3   3   32   2

10   1  1  1  1  1  1  1  1  1   1   1   1   11  1

12   2  2  2  3  2  2  2  1  3   2   1   2   23   3



While doing regression  i1 being the dependent variable and i2 as the
predictor  the outputs produced are not correct.The o/ps are as shown
below:---

*all_raw_data_NAomitted$i1<-as.vector(as.matrix(all_raw_data_NAomitted$i1))
all_raw_data_NAomitted$i2<-as.vector(as.matrix(all_raw_data_NAomitted$i2))
*

*
*

*fit<-lrm(i1 ~ i2 + NULL,all_raw_data_NAomitted)*

> source("regression.R")

[1] "Printing regression value."

Call:

lm(formula = i1 ~ i2, data = all_raw_data_NAomitted)

Residuals:

 Min   1Q   Median   3Q  Max

-1.46154 -0.19277 -0.03529 -0.03529  1.96471

*Coefficients:*

*Estimate Std. Error t value Pr(>|t|)*

*(Intercept)  1.192770.05302   22.50   <2e-16 

*i22  0.842520.06469   13.03   <2e-16 

*i23  1.527230.11021   13.86   <2e-16 

*i24  2.268770.14409   15.74   <2e-16 

---

Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1



Residual standard error: 0.4831 on 287 degrees of freedom

Multiple R-squared: 0.5815, Adjusted R-squared: 0.5771

F-statistic: 132.9 on 3 and 287 DF,  p-value: < 2.2e-16



Error in main() :

In addition: Warning messages:

1: In model.matrix.default(mt, mf, contrasts) :

  variable 'i1' converted to a factor

2: In model.matrix.default(mt, mf, contrasts) :

  variable 'i2' converted to a factor

*The results produced are incorrect and do not match with SPSS results ,you
can find it out having a look at the coefficients sections of the result.my
variables were i1 and i2.*



*CASE-II*

Whereas  if I do this the results produced are correct:--

> d1<-c(1,2,3,NA,6,7,8)

> d2<-c(2,3,4,3,1,2,2)

> d3<-c(2,1,2,1,2,1,3)

> d4<-c(5,6,2,1,1,2,2)

> d<-data.frame(d1,d2,d3,d4)

> d

  d1 d2 d3 d4

1  1  2  2  5

2  2  3  1  6

3  3  4  2  2

4 NA  3  1  1

5  6  1  2  1

6  7  2  1  2

7  8  2  3  2

> fit<-lm(d1 ~ d2+d3+d4)

> summary(fit)



Call:

lm(formula = d1 ~ d2 + d3 + d4)



Residuals:

  1   2   3   5   6   7

-1.7865  0.9698 -1.2250 -1.4802  1.2761  2.2459



Coefficients:

Estimate Std. Error t value Pr(>|t|)

(Intercept)   9.1912 5.1807   1.7740.218

d2   -0.7570 1.2208  -0.6200.598

d30.0151 1.7474   0.0090.994

d4   -0.9842 0.6772  -1.4530.283



Residual standard error: 2.692 on 2 degrees of freedom

  (1 observation deleted due to missingness)

Multiple R-squared: 0.6507, Adjusted R-squared: 0.1267

F-statistic: 1.242 on 3 and 2 DF,  p-value: 0.4751

In case – (I) if I make the individual columns as vectors also ,I do not get
correct results.what could be the cause of the incorrect results produced.


-- 
Thanks
Moumita

[[alternative HTML version deleted]]

__
R-help@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.


[R] How to dynamically generate lm() function arguments?

2009-07-22 Thread Moumita Das
Hi All,
How do you dynamically generate the arguments for the lm() function when
your items vary for each database.
Say in my case for a particular database i have items from i1 to i15 .

In the code below there a line like this :--
 item_cat_fit<-lm(as.numeric(item_item_table$i1) ~
as.numeric(item_item_table$i2) + as.numeric(item_category_table$i3)  ) *#
this gives proper results,i am accessing each column of the dataset using
column names.
*
how do i dynamically generate this :---
item_cat_fit<-lm(as.numeric(item_item_table[item_item_dependent_var_counter])
~  as.numeric(item_item_table[item_item_independent_var_counter ] ) )

*Because of this as.numeric(item_item_table[item_item_dependent_var_counter])
i get error that you cannot convert a list to double.I tried doing this
as.numeric(as.matrix(item_item_table[item_item_dependent_var_counter]))*

I also tried doing this
mode(item_item_table[item_item_dependent_var_counter])<-"numeric"  but of no
use.

for(item_item_dependent_var_counter in 1:item_item_size[1])  # no of all
items
 {


  for(item_item_independent_var_counter in 1:(item_item_size[1] - 1))
  {


item_item_third_var_data<-contrld_third_var(stringOfItemItemToDataFrameOfItemItem[item_item_dependent_var_counter,1],x<-stringOfItemItemToDataFrameOfItemItem,item__table,regr_type<-"ii")


 item_cat_fit<-lm(as.numeric(item_item_table$i1) ~
as.numeric(item_item_table$i2) )
 item_cat_fit<-lm(as.numeric(item_item_table[item_item_dependent_var_counter])
~  as.numeric(item_item_table[item_item_independent_var_counter ] ) )

#print(summary(item_item_fit))
   }
}

How can the lm() arguments be generated dynamically.?Would be grateful if
anyone can come up with a solution for my problem.
-- 
Thanks
Moumita

[[alternative HTML version deleted]]

__
R-help@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.


[R] R : how does %in% operator work?

2009-08-18 Thread Moumita Das
*Problem-1*



CASE-I-(works fine)

> var1<-"tom"

> var1

[1"tom"

>  var1<-as.character(var1)

>  var1

[1] "tom"

>  var2<-c("tom","harry","kate")

> logc<-(var1 %in% var2)

> logc

[1] TRUE

> typeof(var1)

[1] "character"

> typeof(var2)

[1] "character"



*CASE-II-(doesn’t  work)*

I have my dynamically generated dataset on which I want to use this %in%
operator.But it’s not working



*predictors_values data frame is shown below:---*

   x

2  recmeanC2

3  recmeanC3

4  recmeanC4

5 i1

6 i2

7 i3

8 i4

9 i5

10i6

11i7

12i8

13i9

14   i10

15   i11

16   i12

17   i13

18   i14

19   i15

*coef_dataframe_rownames data frame is shown below:*

if (stringsAsFactors) factor(x) else x

1   recmeanC2

2   recmeanC3

3   recmeanC4

4  i1

5  i2

6  i3

7  i4

8  i5

9  i6

10 i7

11 i8

12 i9

13i10

14i12

15i13



*Just pasted a part of my code:--*

predictor<-predictors_values[1,1]

predictor<-as.character(predictor)

predictor<-noquote(predictor)

print("predictor")

print(predictor) ##prints recmeanC1




print("coef_dataframe_rownames")

#coef_dataframe_rownames<-c(coef_dataframe_rownames)

#coef_dataframe_rownames<-c("recmeanC2","recmeanC3"," recmeanC4","i1")
   *#only
when I har –coded in this way I get correct values for logc(you will find
logc below)*

names(coef_dataframe_rownames)<-letters[1]

coef_dataframe_rownames<-c(coef_dataframe_rownames)

print(coef_dataframe_rownames)



#prints

[1] "coef_dataframe_rownames"

$a

 [1] recmeanC2 recmeanC3 recmeanC4 i1i2i3i4

 [8] i5i6i7i8i9i10   i12

[15] i13

print(typeof(predictor))

print(typeof(coef_dataframe_rownames))

logc<-(predictor %in% coef_dataframe_rownames)

print("logc")

print(logc) # prints FALSE

For  logc<-(predictor %in% coef_dataframe_rownames) to work I have changed
the predictor and coef_dataframe_rownames to all different data types ,like
both vectors ,both dats frames, predictor to character and
coef_dataframe_rownames to vector…But nothings seems to work.

[ If predictor  is in coef_dataframe_rownames  do  task 1 else task2 ]

Here predictors_values is a data frame of all possible predictors when one
particular element ‘s regression is to be done.And coef_dataframe_rownames  is
the  data frame of rownames of the coefficients table which was produced as
a result of regression function.

*Problem-2:--*

I wanted something ,as in Problem -1 because of  Problem-2.

Now if some rows of the coefficients  table are filled with NAs in all row
then those rows are getting omitted automatically when I am trying to access
only the coefficients table like this:--



*
fit<-lm(item_category_table[element_n_predictors_string_to_vector],singular.ok=TRUE)
*

*Coefficients<-summary(fit)$coefficients*

Now becausing I am running loops to enter values of “coefficients table “ in
the database tables ,the omission of the rows with all NAs are causing
problems. Even if these rows do not have values I need to populate the data
base tables values for these particular NA row s of the coefficients table.

*Is there any way to get the full coefficients table with out the NA
containing rows being omitted?*



Print  gives this:

[1] "coef_dataframe without intercept"  # I have omitted the intercept
,please don not get confused

Estimate   Std. Error   t value   Pr(>|t|)

recmeanC2  9.275880e-17 6.322780e-17  1.467057e+00 0.14349903

recmeanC3 1.283534e-17 2.080644e-17  6.168929e-01 0.53781390

recmeanC4 -3.079466e-17 2.565499e-17 -1.200338e+00 0.23103743

i1 5.00e-01 1.036197e-17  4.825338e+16
0.

i2   -5.630739e-18 1.638267e-17 -3.437010e-01
0.73133282

i3  4.291387e-18 1.207522e-17  3.553879e-01
0.72257050

i4  1.472662e-17 1.423051e-17  1.034863e+00
0.30163897

i5   5.00e-01 1.003323e-17  4.983441e+16
0.

i6  5.147966e-18 1.569095e-17  3.280850e-01
0.74309614

i7  1.096044e-17 1.555829e-17  7.044760e-01
0.48173041

i8-1.166290e-18 1.287370e-17 -9.059482e-02 0.92788026

i9 1.627371e-17 1.540567e-17  1.056345e+00 0.29173427

i104.001692e-18 1.365740e-17  2.9300

[R] Insert rows in between dataframes

2009-08-20 Thread Moumita Das
Hi all,

Can anyone suggest me how to insert rows in between data frames and also
keep the ordering of row numbers correct?

 Estimate Std. Errort
value   Pr(>|t|)

recmeanC2  9.275880e-176.322780e-17   1.467057e+00
0.14349903

recmeanC3  1.283534e-17   2.080644e-176.168929e-01
0.53781390

recmeanC4 -   3.079466e-172.565499e-17  -1.200338e+00
0.23103743

i15.00e-01
1.036197e-17   4.825338e+16
0.

i2 -5.630739e-18
1.638267e-17  -3.437010e-01
0.73133282

i3 4.291387e-18
1.207522e-17   3.553879e-01
0.72257050

i4 1.472662e-17
1.423051e-17   1.034863e+00
0.30163897

i5   5.00e-011.003323e-17
 4.983441e+16
0.

i6   5.147966e-18 1.569095e-17
 3.280850e-01
0.74309614

i7 1.096044e-17   1.555829e-17
 7.044760e-01
0.48173041

i8-1.166290e-181.287370e-17
-9.059482e-02 0.92788026

i9 1.627371e-17   1.540567e-17
 1.056345e+00
0.29173427

i104.001692e-18   1.365740e-17
 2.930053e-01
0.76973827

i12-1.052843e-17   1.324484e-17
-7.949081e-01 0.42735000

i132.571236e-17   1.357336e-17
 1.894325e+00
0.05922715

This is my coeffcients table.Here  I want ti inser t rows with value NA in
all columns in between and after  the last row.After last  row I can insert
using rbind.But how will I enter row in between so that the order also
doesn’t change.

I need this to be generated :---

Estimate Std. Errort value   Pr(>|t|)

recmeanC2  9.275880e-176.322780e-17   1.467057e+00
0.14349903

recmeanC3  1.283534e-17   2.080644e-176.168929e-01
0.53781390

recmeanC4 -   3.079466e-172.565499e-17  -1.200338e+00
0.23103743

i15.00e-01
1.036197e-17   4.825338e+16
0.

i2 -5.630739e-18
1.638267e-17  -3.437010e-01
0.73133282

i3 4.291387e-18
1.207522e-17   3.553879e-01
0.72257050

i4 1.472662e-17
1.423051e-17   1.034863e+00
0.30163897

i5   5.00e-011.003323e-17
 4.983441e+16
0.

i6   5.147966e-18 1.569095e-17
 3.280850e-01
0.74309614

i7 1.096044e-17   1.555829e-17
 7.044760e-01
0.48173041

i8-1.166290e-181.287370e-17
-9.059482e-02 0.92788026

i9 1.627371e-17   1.540567e-17
 1.056345e+00
0.29173427


i104.001692e-18   1.365740e-17
 2.930053e-01
0.76973827

i11NA
NA  NA
NA

i12-1.052843e-17   1.324484e-17
-7.949081e-01 0.42735000

i132.571236e-17   1.357336e-17
 1.894325e+00
0.05922715

i14 NA
NA  NA
NA



i15 NA
NA  NA
NA





 rbind after row number i10 will change row number i12  to  have NA,Na,NA.Na
values.


-- 
Thanks in advance
Moumita

[[alternative HTML version deleted]]

__
R-help@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.


[R] natural sorting a data frame /vector by row

2009-08-24 Thread Moumita Das
How to  NATURAL sort a vector or data frame* by row*  , in ascending order ?


V1   V2V3 V4
i1 5.00e-01 1.036197e-17  4.825338e+16 0.
i104.001692e-18 1.365740e-17  2.930053e-01 0.76973827
i12   -1.052843e-17 1.324484e-17 -7.949081e-01 0.42735000
i132.571236e-17 1.357336e-17  1.894325e+00 0.05922715
i2-5.630739e-18 1.638267e-17 -3.437010e-01 0.73133282
i3 4.291387e-18 1.207522e-17  3.553879e-01 0.72257050
i4 1.472662e-17 1.423051e-17  1.034863e+00 0.30163897
i5 5.00e-01 1.003323e-17  4.983441e+16 0.
i6 5.147966e-18 1.569095e-17  3.280850e-01 0.74309614
i7 1.096044e-17 1.555829e-17  7.044760e-01 0.48173041
i8-1.166290e-18 1.287370e-17 -9.059482e-02 0.92788026
i9 1.627371e-17 1.540567e-17  1.056345e+00 0.29173427
recmeanC2  9.275880e-17 6.322780e-17  1.467057e+00 0.14349903
 NA   NANA NA
recmeanC3  1.283534e-17 2.080644e-17  6.168929e-01 0.53781390
recmeanC4-3.079466e-17 2.565499e-17 -1.200338e+00 0.23103743



I want a sequence of rows as :--  *recmeanC2 ,recmeanC3,recmeanC4* and the *NA
row  in the third position from the top*(presently it's third from down)
-- 
Thanks
Moumita

[[alternative HTML version deleted]]

__
R-help@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.


[R] How to generate mean anova value row in anova table, instead of individual value for each predictor

2009-08-28 Thread Moumita Das
Hi All ,
Can anybody tell me if there's any way to get the summarized anova
values.Now i will explain what i mean , when i say "*summarized*".

Below you can see the anova table of recmeanC1 with rest* all* i.e from
recmeanC2 to i15(predictors),as shown in table.











  Df Sum SquaresMean Square F valueSignificance [Pr(>F)]
recmeanC21 89.272 89.272 1.50E+34 < 2e-16 ***
recmeanC31 9.965 9.965 1.68E+33  < 2e-16 ***
recmeanC41 2.61 2.61 4.40E+32 < 2e-16 ***
i1   1 25.341 25.341 4.27E+33 < 2e-16 ***
i2   1 0.118 0.118 1.98E+31 < 2e-16 ***
i3   1 0.022 0.022 3.65E+30 < 2e-16 ***
i4   1 0.164 0.164 2.75E+31 < 2e-16 ***
i5   1 15.639 15.639 2.63E+33 < 2e-16 ***
i6   1 1.64E-34 1.64E-34 2.76E-02 0.86812
i7   1 1.72E-33 1.72E-33 2.89E-01 0.59112
i8   1 9.29E-34 9.29E-34 1.57E-01 0.69273
i9   1 6.38E-33 6.38E-33 1.07E+00 0.30092
i10  1 1.02E-32 1.02E-32 1.71E+00 0.19166
i12  1 2.25E-33 2.25E-33 3.80E-01 0.53831
i13  1 2.13E-32 2.13E-32 3.5885e+00 0.53831 0.53831
Regression 15 1.43E+02 9.54E+00 1.61E+33 < 2.2e-16
Residuals  276 1.64E-30 5.94E-33
Total 291 1.43E+02

Instead of the values in the rows from reacmeanC1 to i15...what i want is a
summarized value ,what the row named "*Regression*" shows.I do not get
anything like the row "Regression".I copied that to show that SPSS has way
to generate that.though "Residuals" row is generated in R just like SPSS.

I know the how to calculate a single summarized Df,Sum Sq,Mean Sq,F
value,Pr(>F) with these formulae:---
*That is instead of all the 15 rows from reacmeanC1 to i15 i want row
"Regresssion"*


Df   Sum Sq Mean
SqF value





 Regression Calculations sum of all the above dfs sum of all the above Sum
of Squares Sum of Squares/df Mean Square due to Regression/Mean Square due
to Residuals



But isn't there any function in R to get what i explained above in a much
easier way?

-- 
Thanks in advance
Moumita

[[alternative HTML version deleted]]

__
R-help@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.


[R] Factor Analysis function source code required

2009-09-15 Thread Moumita Das
Hi All,
There were lot of diffrences in the R and SPSS results for Exploratory
Factor Analysis.why is it so ?I used standard factor analysis functions
like:--

factanal(m, factors=3, rotation="varimax")
princomp(m, cor = FALSE, scores = TRUE, subset = rep(TRUE,
nrow(as.matrix(m
print(summary(princomp(m, cor=TRUE),loadings = TRUE, cutoff = 0.2), digits =
2)
prcomp(m, scale = TRUE)
summary(pc.cr <- princomp(m, cor=TRUE))

I just do coding in R ,but my statistician said teh results vary a lot.I
found quite a number of posts regarding this issue in these links:--
https://stat.ethz.ch/pipermail/r-help/2003-May/033299.html
https://stat.ethz.ch/pipermail/r-help/2003-May/033361.html
https://stat.ethz.ch/pipermail/r-help/2003-May/033361.html
https://stat.ethz.ch/pipermail/r-help/2003-May/033299.html
http://tolstoy.newcastle.edu.au/R/help/03a/5100.html

I wanted to use factanal.pa and principal function , i do not find code for
that.I did not want to install teh packages psych and nFactors.Can anyone
help me please

-- 
Thanks
Moumita

[[alternative HTML version deleted]]

__
R-help@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.


[R] How to get the unique pairs of a set of pairs dataframe ?

2009-06-10 Thread Moumita Das
Hi friends,
Please can anyone help me with an easier solution of doing the  below
mentioned work.
Suppose i have a dataset like this:---

i1 i2  i3   i4 i5
1  7  13  1  2
2  8  14  2  2
3  9  15  3  3
4  10 16  4  4
5  11 17  5  5
6  12 18  6  7


*i1,i2,i3,i4,i5 are my items.I am able to find all possible pairs i.e
Say this dataframe is "item_pairs"
**i1,i2
**i1,i3
**i1,i4
i1,i5
**i2,i1
**i2,i3
i2,i4
i2,i5
**i3,i1
**i3,i2
**i3,i4
**i3,i5
**i4,i1
**i4,i2
**i4,i3
i4,i5
i5,i1
i5,i2
i5,i3
i5,i4

Pairs like (i1,i1) or (i2,i2) are not required.Now pair (i1,i2) is same as
pair (i2,i1) .How can i chop off the second pair which is identicle to the
first one,only that sequence of item numbers are different ,otherwise my
dataset is same.

I thought of something...like running loops for all rows and columns of
this item_pairs dataframe and check if first item in a pair matches with any
second item of previous pair and similarly  **second item in a pair matches
with any first item of previous pair* and keep entering them in a dataframe
and get the unique pairs.

But is there any other easier way of chopping off the identicle pairs?
*-- *
Thanks in advance
Moumita

[[alternative HTML version deleted]]

__
R-help@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.