[R] Problems with lm()
Dear R-users: I am a new R-user and I have a question about lm function. Here is my data. a<-c(1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,14,14) b<-c(1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2) c<-c(2,1,1,2,2,1,1,2,2,1,1,2,2,1,1,2,2,1,1,2,2,1,1,2,2,1,1,2) d<-c(2,2,1,1,2,2,1,1,2,2,1,1,2,2,1,1,2,2,1,1,2,2,1,1,2,2,1,1) e<-c(1739,1633,1481,1837,1780,2073,1374,1629,1555,1385,1756,1522,1566,1643,1939,1615,1475,1759,1388,1483,1127,1682,1542,1247,1235,1605,1598,1718 ) Data<-data.frame(subject=as.factor(a), drug=as.factor(b), period=as.factor(c), sequence=as.factor(d), Max=e) lm3<- lm(Max ~subject*sequence + sequence + period + drug, data=Data) print(lm3) anova(lm3) When I use lm to fit the data, there are some problems in “subject*sequence”. I have use GLM in SPSS to fit the same data, and it seems there is no problem. I don’t know where my problem is. How can I get the same result with SPSS? How can I do? Best regards, Hsin-Ya Lee __ [[elided Yahoo spam]] Content-Type: application/msword; name="Result_SPSS.doc" Content-Transfer-Encoding: base64 Content-Description: 3367377201-Result_SPSS.doc Content-Disposition: attachment; filename="Result_SPSS.doc" __ 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] “Check” problem
Dear all: I ‘m a newer. I have some problem when I check my package. The error messages were as follows. It shows that the problem is about Rd file. How can I find where the error is? How can I do?? c:\temp>Rcmd check bear * checking for working pdflatex ... OK * using log directory 'c:/temp/bear.Rcheck' * using R version 2.7.0 (2008-04-22) * using session charset: CP950 * checking for file 'bear/DESCRIPTION' ... OK * this is package 'bear' version '1.0.0' * checking package dependencies ... OK * checking if this is a source package ... OK * checking whether package 'bear' can be installed ... OK * checking package directory ... OK * checking for portable file names ... OK * checking DESCRIPTION meta-information ... OK * checking top-level files ... OK * checking index information ... OK * checking package subdirectories ... OK * checking R files for non-ASCII characters ... OK * checking R files for syntax errors ... OK * checking whether the package can be loaded ... OK * checking whether the package can be loaded with stated dependencies ... OK * checking for unstated dependencies in R code ... OK * checking S3 generic/method consistency ... OK * checking replacement functions ... OK * checking foreign function calls ... OK * checking R code for possible problems ... OK * checking Rd files ... OK * checking Rd cross-references ... OK * checking for missing documentation entries ... OK * checking for code/documentation mismatches ... OK * checking Rd \usage sections ... OK * creating bear-Ex.R ... OK * checking examples ... OK * creating bear-manual.tex ... OK * checking bear-manual.tex using pdflatex ... ERROR LaTeX errors when creating PDF version. This typically indicates Rd problems. LaTeX errors found: Binary file bear-manual.log matches Best regards, Hsin- Ya Lee ___ 總會在某些時刻,突然想起舊情人?他 現在過得還好嗎? http://sev.search.yahoo.net __ 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 find and use specific column after spliting dataframe
Dear all: I am a new R-user and I have 2 questions about it. 1) I need to find specific sub-dataframe, and then use specific column to calculate. For example, after splitting dataframe, I find specific the sub-dataframe, such as “A.split [1]”. But, I don’t know how to find “time” and “concentration” columns of “A.split [1]”. 2) The equation used to sub-dataframe is (time[i]-time[i-1])*(concentration[i]- concentration[i-1])*1/2. I don’t know how to calculate it. How can I find the specific column and use it to calculate ? x<-rep(c(1.2,6.8),4) y<-rep(c(1, 2),4) z<-rep(c(1,2),4) t<-rep(c(0,1,2,3),length.out=8) c<-rep(c(0,0.5,1,2),length.out=8) df<-data.frame(pH=x, formulation=y, subject=z, time=t, concentration=c) A.split<-split(df, list(df$pH ,df$formulation, df$subject) ) A.split [1] Best regards, Hsin-Ya Lee __ 怎樣減少垃圾信?只要看到垃圾信,立即按下「這是垃圾信」按鈕。http://tw.promo.yahoo.com/antispam/index.html __ 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 catch data from the different dataframes and lm problem?
Dear all: I am a new R-user and I have 2 questions about it. 1) I have a dataframe. Based on “formulation” and “subject”, a dataframe is split into 4 dataframes. The example is as follows. Moreover, I want to calculate “test” value for these 4 dataframes. My question is that the “test” values not correct and I do not know where the problem is. 2) There are 12 “test” (y) values from 1). Then, I want to model the relationship between “concentration” (X) and “test” (Y) by fitting the linear regression, such lm(Y~X) and this is my target. I think that if I can catch “test” (Y) values and “concentration” (X) values into a dataframe, then I can carry out regression. So, how to catch all “test” values from different dataframes? Or does anyone have better way to get this target? Example: w<-(c(1,1,1,2,2,2,1,1,1,2,2,2)) y<-(c(1,1,1,1,1,1,2,2,2,2,2,2)) z<-(c(1,2,3,1,2,3,1,2,3,1,2,3)) c<-(c(0.1,10,20,0.3,2.5,6,20,25,60,35,40,45)) df<-data.frame(formulation=y, subject=w, time=z, concentration=c) A.split<-split(df, list(df$formulation, df$subject) ) for (j in 1:length(A.split)){ test <- 0 for(i in 2:length(A.split[[j]][["time"]])){ test[i] <- (A.split[[1]][["time"]][i] - A.split[[1]][["time"]][i-1]) * (A.split[[1]][["concentration"]][i] - A.split[[1]][["concentration"]][i-1])* 0.5 test[i]<-test[i]+test[i-1] } output<-data.frame(A.split[[j]][["subject"]],A.split[[j]][["formulation"]],A.split[[j]][["time"]],A.split[[j]][["concentration"]],test) colnames(output)<-list("subject","formulation","time","concentration","test") show(output) } Best regards, Hsin-Ya Lee _ 馬上體驗全新Yahoo!奇摩電子信箱2.0。 http://tw.mg0.mail.yahoo.com/dc/landing __ 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] Type I SS and Type III SS problem
Dear all: I m a newer on R. I have some problem when I use anova function. I use anova function to get Type I SS results, but I also need to get Type III SS results. However, in my code, there is some different between the result of Type I SS and Type III SS. I don’t know why the “seqe” factor disappeared in the result of Type III SS. How can I do? Here is my example and result. a<-c(1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,14,14) b<-c(1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2) c<-c(2,1,1,2,2,1,1,2,2,1,1,2,2,1,1,2,2,1,1,2,2,1,1,2,2,1,1,2) d<-c(2,2,1,1,2,2,1,1,2,2,1,1,2,2,1,1,2,2,1,1,2,2,1,1,2,2,1,1) e<-c(1739,1633,1481,1837,1780,2073,1374,1629,1555,1385,1756,1522,1566,1643, 1939,1615,1475,1759,1388,1483,1127,1682,1542,1247,1235,1605,1598,1718 ) KK<-data.frame(subj=as.factor(a), drug=as.factor(b), per=as.factor(c), seqe=as.factor(d), Cmax=e) M<- lm(Cmax ~ seqe+ subj:seqe + per + drug , data=KK) anova(M) drop1(M, test="F") The result of Type I SS: Analysis of Variance Table Response: Cmax Df Sum Sq Mean Sq F value Pr(>F) seqe 1 585 585 0.0160 0.9014 per 1 63175 63175 1.7293 0.2131 drug 1 58149 58149 1.5917 0.2311 seqe:subj 12 634325 52860 1.4469 0.2660 Residuals 12 438395 36533 The result of Type III SS: Single term deletions Model: AUCt ~ seqe + subj:seqe + per + drug Df Sum of Sq RSS AIC F value Pr(F) 63208187 442 per 1 2100484 65308672 441 0.3988 0.5396 drug 1 4714183 67922370 442 0.8950 0.3628 seqe:subj 12 35813062 99021249 430 0.5666 0.8308 Best regards, HY Lee _ 想知道無聊生活如何大變身嘛? http://tw.promote.mail.yahoo.com/dc/change.html __ 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] miscalculate AUC
Dear R-helper, I have subject 1, 2, 3 and formulation S, MF, MM. I have a problem in calculating AUC. The AUC (0~t) in formulation MF and MM were miscalculated, but I don’t know where my problem is. Here is my code and output. test<-function( InVVTestindex, separateWindows=TRUE) { for( i in 1:length(unique (InVVTestindex$subject))){ x<-InVVTestindex$time[InVVTestindex$subject==i] y<-InVVTestindex$concentration[InVVTestindex$subject==i] v<-InVVTestindex$formulation[InVVTestindex$subject==i] w<-InVVTestindex$pH[InVVTestindex$subject==i] #calculate AUC add<-function(time,concentration){ auc<-0 for(i in 2:length(time)) { auc[i]<-1/2*(time[i]-time[i-1])*(concentration[i]+concentration[i-1]) auc[i]<-auc[i]+auc[i-1] } return(list(auc=auc)) } add<-add(x,y) AUC<-add$auc #Output cat("<< Output >>\n") output<-data.frame(w,i,v,x,y,AUC) colnames(output)<-list("pH","subject","formulation","time","concentration","AUC(0~t)") show(output) cat("\n\n") } } << Output >> pH subject formulation time concentration AUC(0~t) 1 6.8 1 S 0.0 0.00 0. 2 6.8 1 S 0.5110.26 27.5650 3 6.8 1 S 1.0116.17 84.1725 4 6.8 1 S 1.5130.20 145.7650 5 6.8 1 S 2.0145.77 214.7575 6 6.8 1 S 3.0123.75 349.5175 7 6.8 1 S 4.0123.05 472.9175 8 6.8 1 S 5.0 82.35 575.6175 9 6.8 1 S 6.0 48.62 641.1025 10 6.8 1 S 8.0 26.51 716.2325 11 6.8 1 S 10.0 3.04 745.7825 12 6.8 1 S 12.0 2.87 751.6925 13 6.8 1 S 24.0 2.74 785.3525 14 6.8 1 MF 0.0 0.00 752.4725 15 6.8 1 MF 0.5 91.67 775.3900 16 6.8 1 MF 1.0216.78 852.5025 17 6.8 1 MF 1.5179.91 951.6750 18 6.8 1 MF 2.0187.02 1043.4075 19 6.8 1 MF 3.0176.15 1224.9925 20 6.8 1 MF 4.0171.24 1398.6875 21 6.8 1 MF 5.0157.83 1563.2225 22 6.8 1 MF 6.0149.15 1716.7125 23 6.8 1 MF 8.0142.18 2008.0425 24 6.8 1 MF 10.0107.56 2257.7825 25 6.8 1 MF 12.0 86.37 2451.7125 26 6.8 1 MF 24.0 9.30 3025.7325 27 6.8 1 MM 0.0 0.00 2914.1325 28 6.8 1 MM 0.5114.18 2942.6775 29 6.8 1 MM 1.0160.72 3011.4025 30 6.8 1 MM 1.5152.28 3089.6525 31 6.8 1 MM 2.0125.05 3158.9850 32 6.8 1 MM 3.0118.97 3280.9950 33 6.8 1 MM 4.0123.26 3402.1100 34 6.8 1 MM 5.0143.46 3535.4700 35 6.8 1 MM 6.0137.00 3675.7000 36 6.8 1 MM 8.0 91.48 3904.1800 37 6.8 1 MM 10.0 52.46 4048.1200 38 6.8 1 MM 12.0 15.39 4115.9700 39 6.8 1 MM 24.0 8.00 4256.3100 Best regards, Hsin-Ya Lee __ 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.