I created a frequency graph using ggplot2. I would like the bars to go in descending order based on frequency counts. So language measures from left to right, BNT, WAB_R, BDAE...etc. Of note, my dataframe is organized with the language measures are columns and the cases are rows. The values are 0 or 1 and 1 means that the participant endorsed the language measure. I have tried using reorder in various combinations but had no luck. I appreciate the help!
Here is sample data:
WAB-R BDAE BNT CAT
1 0 0 1 0
2 1 0 1 1
3 0 0 0 0
4 1 1 0 0
5 0 0 0 1
6 0 1 1 0
7 1 0 0 0
8 0 1 1 0
Portion of the Data Show in New WindowClear
OutputExpand/Collapse Output
structure(list(WAB_R = c(0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0), WAB_B = c(1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0), BDAE = c(0, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 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, 0, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0)), row.names = c(NA, -85L), class = c("tbl_df", "tbl", "data.frame"))
Code:
library(tidyverse) survey %>% select(c(WAB_R:other_lang_measure)) %>% pivot_longer(everything()) %>% filter(value==1) %>% ggplot(aes(x= value))+ geom_histogram(stat = 'count',aes(fill=name), position = position_dodge2(0.9,preserve = 'single'))+ labs(fill='Language Measures') + theme(axis.title.x=element_blank(), axis.text.x=element_blank(),axis.ticks.x=element_blank()) + scale_y_continuous(breaks=seq(0,50,5))+ ylab("Frequency Counts") + coord_cartesian(ylim=c(0, 45))+ ggtitle("\nLanguage Measures\n ")+ cleanup
As mentioned by sage #r2evans you would need to format as factor the x-axis variable. Also, you can compute the counts directly using summarise() and then arrange in order to sketch the plot:
library(tidyverse)
#Code
survey %>%
select(c(WAB_R:Compiled_lang)) %>%
pivot_longer(everything()) %>% filter(value==1) %>%
group_by(name) %>%
summarise(value=sum(value)) %>%
arrange(desc(value)) %>%
mutate(name=factor(name,levels = unique(name),ordered = T)) %>%
ggplot(aes(x= name,y=value))+
geom_bar(stat = 'identity',aes(fill=name),
position = position_dodge2(0.9,preserve = 'single'))+
labs(fill='Language Measures') +
theme(axis.title.x=element_blank(),
axis.text.x=element_blank(),axis.ticks.x=element_blank()) +
scale_y_continuous(breaks=seq(0,50,5))+
ylab("Frequency Counts") +
coord_cartesian(ylim=c(0, 45))+ ggtitle("\nLanguage Measures\n ")
Output:
Here is a way:
survey <- structure(list(WAB_R = c(0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0),
BASA = c(0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
Compiled_lang = c(0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0)),
row.names = c(NA, -85L), class = c("tbl_df", "tbl", "data.frame"))
library(tidyverse,warn.conflicts = F)
survey %>%
pivot_longer(everything()) %>%
filter(value==1) %>%
count(name) %>%
ggplot(aes(x= name, y = n)) +
geom_col() +
labs(y = "Frequency Counts", title = "Language Measures", x = "")
survey %>%
pivot_longer(everything()) %>%
filter(value==1) %>%
count(name) %>%
ggplot(aes(x= name, y = n)) +
geom_col() +
labs(y = "Frequency Counts", title = "Language Measures", x = "") +
coord_flip()
Created on 2021-01-15 by the reprex package (v0.3.0)
Related
I have a dataframe with papers and the parameters they reported one-hot encoded:
.
structure(list(CitationKey = c("White2021", "Tunabot2019", "Fujiwara2017",
"Dewar1994a", "Dewar1994b", "Blank2007_BF", "Blank2007_YF", "Katzschmann2018",
"Leftwich2012", "Gibouin2018", "Donley2000_KT", "Donley2000_CM",
"Sepulveda2000_KT", "Sepulveda2000_CM", "Sepulveda2000_YF", "Salumae2013",
"Jezov2012", "Anderson2000", "ShaoXu2019", "Rufo2013", "LauderFlammangAlben2012",
"Low2010", "Chong2009", "Niu2014", "LiuHu2005", "LiuHu2010",
"Tan2006", "Zhang2010", "Zhong2018a", "Zhong2018b", "ZhongDu2016",
"Xie2020", "Struebig2020", "Bainbridge1958_CD", "Bainbridge1958_T",
"Bainbridge1958_G", "Videler1991_PV", "Videler1991_TS", "Videler1991_AF",
"Videler1991_SScom", "Videler1991_GM", "Videler1991_TT", "Videler1991_OM"
), COM = c(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0), Duty_Cycle = c(1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), `Re ` = c(1, 0, 0, 0, 0,
0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), Flow_Speed = c(1,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
), Drag_Force = c(1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), Speed_Efficiency = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0)), row.names = c(NA, -43L), class = c("tbl_df",
"tbl", "data.frame"))
Using this thread, I was able to make a correlation matrix
reduced_df[,2:ncol(reduced_df)] %>%
cor(use="pairwise.complete.obs", method='spearman') %>%
ggcorrplot(show.diag = F,
type="lower",
lab=TRUE,
lab_size=2)
However, COM and Duty_Cycle, for example have a value of 1.0 because they are both present in the same paper once, and then neither are reported in any other papers - so they correlate exactly. Frequency and COT, however, are co-reported in 8 papers and then vary, so they don't correlate well. I'd like to alter the correlation matrix to show the frequency of both parameters being co-reported in the same papers. COT and Frequency should be 8x higher in value than COM and Duty Cycle.
However, I don't know how to do this. I'd greatly appreciate any advice or ideas.
I am trying to count how many enterprise zones were designated in two specific years out of 8 total years. I first isolated the years with the following code:
ez <- ezunem %>% select(3,7,8)
Then tried to count the enterprise zones that were in the select columns:
ez %>% count(ez, sort=TRUE)
This didnt work. What is the best way to count dummy variables = 1 out of two columns in R.
Edit: here is the output with dput(ez) command:
structure(list(ez = structure(c(0, 0, 0, 0, 1, 1, 1, 1, 1, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1,
1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0,
0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0,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, 0, 0, 0, 0, 0,
1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1,
0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0,
0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0,
0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0,
0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0,
0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,
0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0), format.stata = "%9.0g")), row.names = c(NA,
-198L), class = c("tbl_df", "tbl", "data.frame"))
So, basically I want my output to count the 1's for d84 and d85.
Something like this?
library(dplyr)
ez %>%
group_by(ez) %>%
summarise(across(c(d84, d85), sum, .names="count_{.col}"))
ez count_d84 count_d85
<dbl> <dbl> <dbl>
1 0 16 12
2 1 6 10
I work with mark-recaptures of animals, and I have two capture histories I need to merge. Both files look like this:
Both files include subsets of the same group of animals, however, all inividuals are not present in both files. Also, one file contains more YEARS (in columns) than the other. The 0's and 1's indicate whether the animal was observed this year or not.
I need to merge both files, ending up with a file that contains all individuals that are included in these files. Observation data need to be merged for those individuals that are present in both files. If observation status for a given animal is 0 in FILE1 and 0 in FILE2, the observation status in the merged file need to be 0, if 0 in FILE1 and 1 in FILE2, observation status in the merged file should be 1, and if 1 in both files, it still needs to be 1 in the merged file (NOT 2).
Below you'll find samples of both files, FILE1 and FILE2. Any help appreciated.
FILE1:
> dput(FILE1)
structure(list(ID = c("1", "LL-30", "M-300", "NKW-001", "NKW-002",
"NKW-003", "NKW-004", "NKW-006", "NKW-007", "NKW-009", "NKW-010",
"NKW-011", "NKW-012", "NKW-013", "NKW-014", "NKW-015", "NKW-016",
"NKW-017", "NKW-018", "NKW-019", "NKW-021", "NKW-022", "NKW-023",
"NKW-024", "NKW-025", "NKW-026", "NKW-028", "NKW-029", "NKW-030",
"NKW-031", "NKW-032", "NKW-033", "NKW-034", "NKW-035", "NKW-036",
"NKW-037", "NKW-038", "NKW-039", "NKW-040"), `1986` = c(0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), `1987` = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), `1988` = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), `1989` = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), `1990` = c(0,
0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), `1991` = c(0,
0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), `1992` = c(0,
0, 1, 0, 0,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
-39L))
FILE2:
> dput(FILE2)
structure(list(ID = c("KI03", "KI05", "KI06", "KI07", "KI08",
"KI10", "NKW-001", "NKW-004", "NKW-005", "NKW-009", "NKW-019",
"NKW-023", "NKW-025", "NKW-027", "NKW-031", "NKW-032", "NKW-040",
"NKW-045", "NKW-424", "NKW-431", "NKW-441", "NKW-443"), `2008` = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0
), `2009` = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0), `2010` = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), `2011` = c(0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1), `2012` = c(0,
0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1
), `2013` = c(1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 1, 0, 0, 0), `2014` = c(0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), `2015` = c(1, 1, 1, 0, 1, 1,
1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0), `2016` = c(1,
0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 0
), `2017` = c(1, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0,
0, 0, 1, 0, 0, 0), `2018` = c(1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), `2019` = c(0, 0, 0, 1, 1, 1,
0, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 0), `2020` = c(0,
0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
)), class = "data.frame", row.names = c(NA, -22L))
Here is a scalable data.table solution with no merging involved.
If you have got more files, just add them to the list L
library( data.table )
setDT(df1);setDT(df2) #set to data.table format
L <- list( df1, df2 ) #put the data.tables in a list
#melt all data.tables in the list to long format
L.melt <- lapply( L, melt, id.vars = "ID", variable.name = "year", variable.factor = FALSE )
#rowbind to one large data.table
DT <- data.table::rbindlist( L.melt, use.names = TRUE, fill = TRUE )
#summarise, output a logical TRUE (=1) of FALSE = 0 based on the sum of 0's and 1's
ans <- DT[, .( seen = as.numeric( sum(value) > 0 ) ), by = .(ID, year) ]
#cast to wide again, fill in missing observations in years with 0
dcast( ans, ID ~ year, value.var = "seen", fill = 0 )
Hello wonderful community!
I am having trouble working with a list of lists, each containing 4 DF. I only provide two lists here but I have 54. What I want to do: (1) I want to summarize the amount of rows in each "Comm". (2) I want to drop "comm". (3) I want to combine all of the other elements in each list, into one data frame.
Data below
I have tried all these approaches as well as others.
R list of lists to data.frame
R - list to data frame
Export each data frame within a list to csv
Any ideas on how to do this? Thanks!
> dput(c(output$`2000-Fall`,output$`2001-Spring`))
list(Comm = structure(c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0,
0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0,
0, 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 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), .Dim = c(37L,
27L), .Dimnames = list(NULL, c("AS", "LNS", "SC", "BND", "RT",
"LND", "EBT", "BM", "CS", "BT", "BB", "WS", "GS", "CP", "YB",
"F", "P", "LMB", "YP", "RP", "B", "TD", "AE", "CCS", "A", "FSS",
"M"))), Coherence = structure(list(name = structure(c(1L, 6L,
3L, 4L, 5L, 2L), .Label = c("embAbs", "method = r1", "p", "simMean",
"simVariance", "z"), class = "factor"), stat = c(200, 11.3001899623484,
1.30934461418281e-29, 604.17, 35.7666553701019, NA)), class = "data.frame", row.names = c(NA,
-6L)), Turnover = structure(list(name = structure(c(5L, 6L, 2L,
3L, 4L, 1L), .Label = c("method = EMS", "p", "simMean", "simVariance",
"turnover", "z"), class = "factor"), stat = c(10893, -6.01765438449338,
1.7696251436801e-09, 5823.65, 842.412952971008, NA)), class = "data.frame", row.names = c(NA,
-6L)), Boundary = structure(list(name = structure(c(2L, 3L, 1L
), .Label = c("df", "index", "p"), class = "factor"), stat = c(2.17647058823529,
8.59400834470891e-05, 34)), class = "data.frame", row.names = c(NA,
-3L)), Comm = structure(c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0,
0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1,
0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0,
1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1,
0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0,
0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0,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, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), .Dim = 33:32, .Dimnames = list(
NULL, c("TT", "BM", "LC", "RT", "SC", "CS", "AS", "CRC",
"LND", "BND", "EBT", "BT", "TD", "BL", "F", "SMB", "WS",
"RP", "P", "GSF", "YP", "AE", "CP", "LMB", "YB", "BS", "BB",
"GS", "B", "FSS", "K", "M"))), Coherence = structure(list(
name = structure(c(1L, 6L, 3L, 4L, 5L, 2L), .Label = c("embAbs",
"method = r1", "p", "simMean", "simVariance", "z"), class = "factor"),
stat = c(261, 8.8243058044828, 1.10140877775716e-18, 611.43,
39.711905702767, NA)), class = "data.frame", row.names = c(NA,
-6L)), Turnover = structure(list(name = structure(c(5L, 6L, 2L,
3L, 4L, 1L), .Label = c("method = EMS", "p", "simMean", "simVariance",
"turnover", "z"), class = "factor"), stat = c(10074, -4.74001047198576,
2.13707173521215e-06, 5701.71, 922.422012744687, NA)), class = "data.frame", row.names = c(NA,
-6L)), Boundary = structure(list(name = structure(c(2L, 3L, 1L
), .Label = c("df", "index", "p"), class = "factor"), stat = c(1.82705314009662,
0.000113336323694813, 30)), class = "data.frame", row.names = c(NA,
-3L)))
The object shown in the question is not a list of lists of 4 data frames each so if we call that object L then to get what is described we need to create LL like this. Now using LL we can compute the 3 items requested.
LL <- list(L[1:4], L[5:8])
res1 <- sapply(LL, function(x) nrow(x$Comm))
res2 <- lapply(LL, function(x) x[names(x) != "Comm"])
res3 <- lapply(LL, function(x) do.call("rbind", x[names(x) != "Comm"]))
I'm working with betareg package for beta regression but receive the below error:
Error in optim(par = start, fn = loglikfun, gr = gradfun, method = method, :
non-finite value supplied by optim
I can trace this error to creating the initial values for optim. Specifically, these lines of betareg.fit, which uses lm.wfit to generate starting values.
It turns out that one of the starting values is returned as NA for my dataset. I'm unsure why this is the case, since there are no missing values in the data / input to lm.wfit.
Reproducible example to see NA
## data -- a sample of 100 obs from my actual data
nobs <- 100L
w <- rep(1, nobs)
offset <- rep(0, nobs)
y <- stats::rbeta(nobs, 0.75, 1.658)
x <- structure(c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.0165928242550604,
0.0984749494334759, 0.05517578125, 0.0185352577155742, 0.168701442841287,
0.0514759697487192, 0.026507054296708, 0.0188496858385694, 0.108620689655172,
0.0722387772757858, 0.0272373540856031, 0.0538907902524382, 0.0295235311312482,
0.0318257956448911, 0.231788079470199, 0.0674772036474164, 0.14846108458939,
0.0969908238068386, 0.0441553321506012, 0.154121863799283, 0,
0.110460389247421, 0.0292207792207792, 0.0522853185595568, 0.205288796102992,
0.00961124552835874, 0.0546908714289824, 0.0268199233716475,
0.0253164556962025, 0.181780542384243, 0.0551724137931034, 0.128842504743833,
0.0751429349305745, 0.217853751187085, 0.0510314875135722, 0.108407709439207,
0.04, 0.0638009815535624, 0.128329297820823, 0.0398115958281933,
0.0513258247605534, 0.0520833333333333, 0.0956239870340357, 0.0742899497995351,
0.144527098831031, 0.0723209169054441, 0.140116763969975, 0.172426847735821,
0.00830471112933819, 0.0548386400835806, 0.0372010221576987,
0.0549927641099855, 0.0386658431130327, 0.0256367439122648, 0.0166402535657686,
0.0769230769230769, 0.0130681818181818, 0.0229684699649666, 0.0344827586206897,
0.0135106607557526, 0.0581090909090909, 0.0321364452423698, 0.0141176470588235,
0.0203003337041157, 0.0948080795499367, 0.0202898550724638, 0.0443828016643551,
0.105830475257227, 0.0482315112540193, 0.0394736842105263, 0,
0.071608040201005, 0.0416666666666667, 0.268330928934329, 0.0422895357985838,
0.127678318597993, 0.037029330162505, 0.0328938677375888, 0.10183299389002,
0.0628212450028555, 0.0283431291591781, 0.0690879300928454, 0.134792626728111,
0.0770505385252693, 0.174605316421536, 0.0842012497997116, 0.068774108570891,
0.137089781654799, 0.00986436498150432, 0.0812065297585365, 0.0904255319148936,
0.0205776173285199, 0.0124064303568112, 0.0229630147033144, 0.0578925872983459,
0.0709677419354839, 0.0640070144673389, 0.106259964391839, 0.0315146661646867,
0.0356999429308195, 0.0268438884545218, 0.0748295057905382, 0.0556640625,
0.021107943539976, 0.199778024417314, 0.0175652598194682, 0.0487387772552373,
0.00289995166747221, 0.0672413793103448, 0.101364990868019, 0.0233463035019455,
0.0732353773706287, 0.022508038585209, 0.0368509212730318, 0.101545253863135,
0.0158054711246201, 0.152565574210159, 0.123442866663249, 0.0672186083185492,
0.129032258064516, 0, 0.104565780781544, 0.0551948051948052,
0.03601108033241, 0.160055671537926, 0.02201309207499, 0.0668891510112489,
0.0421455938697318, 0.0632911392405063, 0.234027661399237, 0.0206896551724138,
0.0950664136622391, 0.0936564116526001, 0.183475783475783, 0.0466883821932682,
0.088748974363268, 0.0422641509433962, 0.0467084108986292, 0.0920096852300242,
0.0401480318492767, 0.05103760198652, 0.0208333333333333, 0.0470016207455429,
0.0887666928515318, 0.075451647183847, 0.0310601719197708, 0.0928685551212356,
0.148991255923013, 0.0204541959296663, 0.0689569784090949, 0.0356901206750445,
0.0680173661360347, 0.0508956145768993, 0.0320699343321964, 0.0293185419968304,
0.0659340659340659, 0.00284090909090909, 0.0402373780415312,
0, 0.0230103440996411, 0.0629090909090909, 0.0229802513464991,
0, 0.00778642936596218, 0.0745676859521289, 0.0191304347826087,
0.0443828016643551, 0.0975012248897599, 0.00964630225080386,
0, 0, 0.0678391959798995, 0.05, 0.167973405256225, 0.0427812745869394,
0.197810150080232, 0.0363158937772493, 0.0415070411371503, 0.109979633401222,
0.0285551113649343, 0.0348520911254675, 0.0730930274895321, 0.119239631336406,
0.087821043910522, 0.251855350155175, 0.0668162153501042, 0.0731018910527801,
0.0945505662261226, 0.0530209617755857, 0.0879397164898608, 0.0531914893617021,
0.0339350180505415, 0.0144171389279045, 0.0176020675444417, 0.0758627731264039,
0.0387096774193548, 0.0791319596668128, 0.0898373582199164, 0.0641540015091306,
0.0308596309526326, 0.0853097037616193, 0.145443642937691, 0.134765625,
0.0735152424185233, 0.207547169811321, 0.0712368870456209, 0.1626763574177,
0.0128081198646689, 0.096551724137931, 0.130923771988849, 0.0525291828793774,
0.230005661202748, 0.0833089739842151, 0.123953098827471, 0.344370860927152,
0.0419452887537994, 0.188428900927962, 0.237145640026657, 0.184407648334319,
0.211469534050179, 0.0576923076923077, 0.182300929925301, 0.165584415584416,
0.0806786703601108, 0.274298306657388, 0.0837699832267066, 0.137316953882448,
0.157088122605364, 0.10126582278481, 0.260575112627044, 0.0413793103448276,
0.198292220113852, 0.177511570922951, 0.296296296296296, 0.139522258414767,
0.138297694201175, 0.0645283018867925, 0.12692502961584, 0.162227602905569,
0.0730066165750813, 0.142559418233416, 0.239583333333333, 0.152350081037277,
0.204935285553934, 0.155154091392136, 0.0889398280802292, 0.135152787965875,
0.235552733134678, 0.0947352232531912, 0.154476512637182, 0.137157008940595,
0.162083936324168, 0.138789376158122, 0.104513252539252, 0.0935023771790808,
0.120879120879121, 0.0133522727272727, 0.0824038693376326, 0.0344827586206897,
0.0789529237914292, 0.133527272727273, 0.0569120287253142, 0.0117647058823529,
0.0233592880978865, 0.158352535758029, 0.0527536231884058, 0.104022191400832,
0.201371876531112, 0.0289389067524116, 0.144736842105263, 0,
0.10678391959799, 0.0583333333333333, 0.233080348742395, 0.127753737214791,
0.233930088412044, 0.13375941339675, 0.13934317947634, 0.338085539714868,
0.0805254140491148, 0.101811822995094, 0.167819649250561, 0.142857142857143,
0.227009113504557, 0.254081770341384, 0.155103348822304, 0.161162856336438,
0.124957303134607, 0.155363748458693, 0.214043708410037, 0.111702127659574,
0.126714801444043, 0.0475465770701011, 0.195590169850639, 0.204512967122728,
0.158064516129032, 0.306298407131375, 0.191432758458608, 0.179792327044226,
0.072245355202807, 0.286421683606985, 0.19797912900281, 0.32275390625,
0.4288140812333, 0.180910099889012, 0.165406196633325, 0.539974348011971,
0.0396326727887869, 0.205172413793103, 0.528357204652504, 0.0953307392996109,
0.456736831270425, 0.312189418298743, 0.440536013400335, 0.322295805739514,
0.185410334346505, 0.289871801748646, 0.277182549853899, 0.478218016952494,
0.186379928315412, 0.730769230769231, 0.312846181208395, 0.573051948051948,
0.104916897506925, 0.251913709116214, 0.240451839867001, 0.390675796196668,
0.314176245210728, 0.151898734177215, 0.321921116708234, 0.191379310344828,
0.352371916508539, 0.384971413013885, 0.245204178537512, 0.314060803474484,
0.177397478189521, 0.128301886792453, 0.418175664240988, 0.0532687651331719,
0.263429404508243, 0.351343561546648, 0.520833333333333, 0.160453808752026,
0.40037131675589, 0.0701381509032944, 0.139484240687679, 0.208627671654089,
0.302720922280299, 0.464089813912954, 0.325967367919772, 0.509502256498519,
0.357452966714906, 0.387770228536133, 0.389464763566684, 0.401743264659271,
0.450549450549451, 0.0741477272727273, 0.371069078965643, 0.0344827586206897,
0.351488283723876, 0.394836363636364, 0.10394973070018, 0.0164705882352941,
0.0661846496106785, 0.247721658259119, 0.271552795031056, 0.375866851595007,
0.326800587947085, 0.090032154340836, 0.302631578947368, 0, 0.293969849246231,
0.0916666666666667, 0.262623094775136, 0.37765538945712, 0.437246326652613,
0.553230281411019, 0.553700229860763, 0.327902240325866, 0.18275271273558,
0.23291397483849, 0.407002852114813, 0.115207373271889, 0.569179784589892,
0.306166509243017, 0.536532606954014, 0.426756985605419, 0.214233164297538,
0.515413070283601, 0.401348069939186, 0.23936170212766, 0.406859205776173,
0.301968017675986, 0.46031385697156, 0.417500510516643, 0.280645161290323,
0.545082566125968, 0.308916785607088, 0.40121177121836, 0.110259770455074,
0.573885848318999, 0.0979737591064492, 0.05517578125, 0.43828037308911,
0, 0.0195169553549646, 0.106028217186832, 0.0224746254229096,
0.0913793103448276, 0.149860617129674, 0.0214007782101167, 0.138210545276756,
0.499269219526454, 0.351758793969849, 0, 0.0613981762917933,
0.172457222550019, 0.257446045009484, 0.141730731322689, 0.129032258064516,
0, 0.218723004217694, 0.116883116883117, 0.0207756232686981,
0.00150777081883554, 0.598457747628731, 0.310768434074628, 0.0344827586206897,
0.0759493670886076, 0, 0.0620689655172414, 0.0992409867172676,
0.175878028859243, 0.0207027540360874, 0.342562432138979, 0.0380448433496877,
0.0252830188679245, 0.138432898967676, 0, 0.510037007962319,
0.150097552323519, 0.0520833333333333, 0, 0.200037592718361,
0, 0.0220057306590258, 0.107599706582795, 0.0987006008499829,
0.381862921002717, 0.310497634940381, 0.266713526509752, 0.221418234442836,
0.376899320568252, 0.147387273053657, 0.412044374009509, 0.137362637362637,
0.266761363636364, 0.482401647112941, 0, 0.496200126662445, 0.145890909090909,
0.00933572710951526, 0, 0.000278086763070078, 0.0862344564156858,
0.598343685300207, 0.208044382801664, 0.171974522292994, 0.0418006430868167,
0.0921052631578947, 0, 0.268844221105528, 0.0333333333333333,
0.0333061531706705, 0.330841856805665, 0, 0.228289734443123,
0.226188274459035, 0.0712830957230143, 0.0177041690462593, 0.0492786710059746,
0.246950664482068, 0.00576036866359447, 0.0306545153272577, 0,
0.0744271751321904, 0.198701665255433, 0.268701227042224, 0.196054254007398,
0.0790648033408067, 0.0531914893617021, 0.00144404332129964,
0.620702802934266, 0.28496257232331, 0.197569940780069, 0.170967741935484,
0, 0.0478844352441583, 0.210611453120438, 0.0129145441863414,
0.000260620276257493, 0.208709971897542, 0.3251953125, 0.0114926544356481,
0.194228634850166, 0.640644059526714, 0.0280034202650705, 0.885693571773804,
0.313793103448276, 0.00884360280688263, 0.739299610894942, 0.0108913821054528,
0.00380005846243788, 0, 0, 0.610942249240122, 0.0171968030896315,
0, 0.0280898876404494, 0.100358422939068, 0.173076923076923,
0.0244422988973017, 0.0227272727272727, 0.62292243767313, 0.0628624449083739,
0.00386676364499993, 0.00405650335164993, 0.314176245210728,
0.126582278481013, 0.000798493705700851, 0.581034482758621, 0.0829222011385199,
0.0245031309556221, 0.00588793922127255, 0.0293159609120521,
0.380448433496877, 0.353207547169811, 0.0531392790658318, 0.414043583535109,
0.0632499719636649, 0.096842852075204, 0.0416666666666667, 0.494327390599676,
0.00292230188016789, 0.476089266737513, 0.557478510028653, 0.113709215510918,
0.0199428459772361, 0.00563900138411852, 0.0115416622646005,
0.0101230399337831, 0.0419681620839363, 0.00197652872143298,
0.164294749497994, 0.00475435816164818, 0.137362637362637, 0.584090909090909,
0.000167333519259466, 0.885057471264368, 0.00401097741186405,
0.109381818181818, 0.647935368043088, 0.948235294117647, 0.50139043381535,
0.188100724502294, 0.00447204968944099, 0.105409153952843, 0.0264576188143067,
0.765273311897106, 0.368421052631579, 0.841726618705036, 0.0766331658291457,
0.241666666666667, 0.0153672458132096, 0.0698269079464988, 0.00169902148947551,
0.00340864050733254, 0.00261565695262755, 0.0366598778004073,
0.572815533980582, 0.430635838150289, 0.0247284422598459, 0.285714285714286,
0.00165700082850041, 0.00580218593981919, 0.071062329754847,
0.0487345940351868, 0.0753895267873565, 0.00986436498150432,
0.0469890478271147, 0.340425531914894, 0.216967509025271, 7.16946330049502e-05,
0.0013271400132714, 0.0275678987134981, 0.0806451612903226, 0.00146134736226801,
0.0792675274278758, 0.0146813198032706, 0.472691340280273, 0.00295369646425159,
0.1175738808241, 0.0419921875, 0.00405272515967538, 0.048834628190899,
0.0239082703098317, 0.0611372381359555, 0.00894151764137264,
0.0827586206896552, 0.00552725175430164, 0.0330739299610895,
0.0168742441007694, 0.00701549254603917, 0.0100502512562814,
0, 0.0115501519756839, 0.0167676876039264, 0, 0.0364675734279519,
0.046594982078853, 0.0384615384615385, 0.0193480359774379, 0.0275974025974026,
0.0647506925207756, 0.0440733008582695, 0.0107987353233683, 0.0128455939468915,
0.10727969348659, 0.455696202531646, 0.000897073175540462, 0.0344827586206897,
0.0244781783681214, 0.0400217805608494, 0.0260208926875594, 0.0282301845819761,
0.0483765635727323, 0.295849056603774, 0.11034015907937, 0.150121065375303,
0.00336436021083324, 0.101764810216389, 0.0416666666666667, 0.0502431118314425,
0.0128435876929952, 0.0786397449521785, 0.065214899713467, 0.107117376930575,
0.0130062038981974, 0.0127646485876865, 0.0243222483755186, 0.00109047672226346,
0.0419681620839363, 0.00148239654107474, 0.0995579008011222,
0.0182250396196513, 0.010989010989011, 0.0190340909090909, 0.000341111490123878,
0.0114942528735632, 0.00960523538104285, 0.0609454545454545,
0.108617594254937, 0.00941176470588235, 0.370689655172414, 0.0941230200743186,
0.00919254658385093, 0.0527045769764216, 0.0416462518373346,
0.0128617363344051, 0.0263157894736842, 0.100719424460432, 0.0628140703517588,
0.383333333333333, 0.013861882958038, 0.00324547600314713, 0.00163609476764308,
0.00522195798652398, 0.00245713228883194, 0.00814663951120163,
0.0422615648201028, 0.0899839704667994, 0.00467261362946781,
0.165898617511521, 0.00662800331400166, 0.00748886789906895,
0.00480692196763339, 0.00997271615391853, 0.0314314616779211,
0.0357583230579531, 0.0671742820918722, 0.0585106382978723, 0.193501805054152,
0.000332402389386587, 0.00658331296056997, 0.00745354298550133,
0.106451612903226, 0.00401870524623703, 0.120851102817492, 0.0428155973269565,
0.222051954091015, 0.00773173486230562, 0.0590151610073926, 0.00927734375,
0.00420172240819286, 0, 0.0102464015613564, 0.0269345874305259,
0.00869985500241663, 0.0344827586206897, 0.00288378352398347,
0.00778210116731518, 0.0201551684207818, 0.0423852674656533,
0.0050251256281407, 0, 0.00547112462006079, 0.0142509252802661,
0.00779207463987287, 0.019712201852947, 0.043010752688172, 0,
0.0273133797449057, 0.00974025974025974, 0.0176592797783934,
0, 0.0310305927058439, 0.022756696107483, 0.00383141762452107,
0, 0, 0.0137931034482759, 0.0187855787476281, 0.0283147291042744,
0.00455840455840456, 0.0485884907709012, 0.0202783033875316,
0.0505660377358491, 0.0424775765781012, 0, 0.0069530111023887,
0.055028378857751, 0.03125, 0, 0.0158332727475844, 0, 0.0234957020057307,
0.0948079222645377, 0.00865859020077182, 0.0121494848003281,
0.0493989553698703, 0.00252254856234439, 0.0520984081041968,
0.0035206917850525, 0.0370753822968285, 0.0237717908082409, 0,
0.0267045454545455, 0.000411111567901742, 0, 0.0232214481739498,
0.0344, 0.0181328545780969, 0, 0.0100111234705228, 0.0560918394884889,
0.0242650103519669, 0.0651872399445215, 0.0284174424301813, 0.00321543408360129,
0.0263157894736842, 0.0575539568345324, 0.0515075376884422, 0.1,
0.00545694034999686, 0.00560582218725413, 0, 0.00274474831549742,
0.00129461808766414, 0.00610997963340122, 0.0125642490005711,
0.032180502258707, 0.00664482068086656, 0.0305299539170507, 0,
0, 0.00705015221919564, 0.0127951829899332, 0.0536469691794319,
0.0246609124537608, 0.022233842142586, 0.0531914893617021, 0,
0.00255493601254004, 0.0106578656328944, 0.0116397794568103,
0.0935483870967742, 0, 0.0555500678330224, 0.0552188638129316,
0.0432774619010378, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0,
0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0,
0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 0, 0,
0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0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 1, 1, 1, 1, 1,
1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,
1, 0, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1,
1, 1, 0), .Dim = c(100L, 35L), .Dimnames = list(c("2801", "2316",
"382", "8062", "2687", "2731", "8019", "5652", "8429", "3479",
"7753", "9001", "2188", "8121", "8478", "5817", "1528", "2460",
"3946", "3531", "3421", "2802", "1975", "3639", "2894", "5897",
"9331", "9490", "7135", "5858", "7724", "9414", "9095", "6601",
"5064", "7111", "3593", "7322", "9522", "7116", "6922", "5172",
"2458", "5199", "1387", "3878", "6119", "8722", "6378", "4661",
"6109", "3682", "5751", "9390", "7915", "5268", "1029", "5953",
"242", "2912", "8798", "9607", "9768", "2222", "8260", "851",
"4205", "1823", "5063", "4189", "7541", "608", "6849", "7220",
"2889", "6770", "7064", "646", "4919", "1404", "120", "9716",
"7722", "7700", "6638", "8176", "5745", "6", "9481", "2233",
"341", "228", "1543", "553", "9709", "9493", "881", "7647", "6039",
"2925"), c("(Intercept)", "x 1", "x 2", "x 3", "x 4", "x 5",
"x 6", "x 7", "x 8", "x 9", "x 10", "x 11", "x 12", "x 13", "x 14",
"x 15", "x 16", "x 17", "x 18", "x 19", "x 20", "x 21", "x 22",
"x 23", "x 24", "x 25", "x 26", "x 27", "x 28", "x 29", "x 30",
"x 31", "x 32", "x 33", "x 34")))
Inside betareg: the NA that causes the problem
linkfun <- function(mu) {.Call(stats:::C_logit_link, mu)}
auxreg_test <- lm.wfit(x, linkfun(y), w, offset)
# problem:
(beta <- auxreg_test$coefficients)
is.na(beta['x 8'])
> beta['x 8']
x 8
NA
I originally thought this might be related to using the CRAN version of betareg (3.1-0). But I updated to the rforge version (3.2-0) via devtools::install_github("rforge/betareg/pkg") and still have the same problem.
If I remove the offending predictor from my formula, betareg runs fine; however, the predictor is a necessary one.
NA coefficients from glm / lm / lm.fit / .lm.fit / lm.wfit imply the model matrix to be rank-deficient. They are just 0 with 0 standard error (i.e., fixed at 0).
I appreciated that you have done much debugging work and located the source of the error, but giving us a model matrix x directly is less informative for us to investigate. It would be good if you show us the model formula and the data frame.
Anyway, I have (with some pain) found the collinearity problem from your model matrix.
rowSums(, x[, 2:9])
#2801 2316 382 8062 2687 2731 8019 5652 8429 3479 7753 9001 2188 8121 8478 5817
# 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
#1528 2460 3946 3531 3421 2802 1975 3639 2894 5897 9331 9490 7135 5858 7724 9414
# 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
#9095 6601 5064 7111 3593 7322 9522 7116 6922 5172 2458 5199 1387 3878 6119 8722
# 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
#6378 4661 6109 3682 5751 9390 7915 5268 1029 5953 242 2912 8798 9607 9768 2222
# 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
#8260 851 4205 1823 5063 4189 7541 608 6849 7220 2889 6770 7064 646 4919 1404
# 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
# 120 9716 7722 7700 6638 8176 5745 6 9481 2233 341 228 1543 553 9709 9493
# 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
# 881 7647 6039 2925
# 1 1 1 1
Columns x1 to x8, if all included, has collinearity problem with the intercept (strange; those columns are not dummy ones so they are not from factor variables). If you don't want to drop any of them, drop intercept instead.